VB to C# conversion incongruency with lambdas

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2011-01-06T02:27:50Z Indexed on 2011/01/06 2:54 UTC
Read the original article Hit count: 260

Filed under:
|
|
|
|

I have a bit of code that I have been tasked with converting to C# from VB. A snippet of mine seems like it cannot be converted from one to the other, and if so, I just don't know how to do it and am getting a little frustrated.

Here's some background:

OrderForm is an abstract class, inherited by Invoice (and also PurchaseOrder). The following VB snippet works correctly:

Dim Invs As List(Of OrderForm) = GetForms(theOrder.OrderID)
....
Dim inv As Invoice = Invs.Find(
    Function(someInv As Invoice) thePO.SubPONumber = someInv.SubInvoiceNumber)

In C#, the best I came to converting this is:

List<OrderForm> Invs = GetForms(theOrder.OrderID);
....
Invoice inv = Invs.Find(
    (Invoice someInv) => thePO.SubPONumber == someInv.SubInvoiceNumber);

However, I get the following error when I do this:

Cannot convert lambda expression to delegate type 'System.Predicate' because the parameter types do not match the delegate parameter types

Is there any way to fix this without restructuring my whole codebase?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET