Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3627562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:54:15+00:00 2026-05-18T23:54:15+00:00

I have a bit of code that I have been tasked with converting to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:54:16+00:00Added an answer on May 18, 2026 at 11:54 pm

    I’m guessing that OrderForm derives from Invoice. If so, rewrite your lambda to omit the explicit type declaration inside the Find. (Can’t say with certainty for VB, but for C#, the type is not required in a lambda, it will be inferred.)

    Invoice inv = Invs.Find(someInv => thePO.SubPONumber == someInv.SubInvoiceNumber); 
    

    Edit

    Based on your comment, you’re going to have to do some casting inside the lambda and also to the result.

    Invoice inv = (Invoice)Invs.Find(someInv => 
                       thePO.SubPONumber == ((Invoice)someInv).SubInvoiceNumber);  
    

    Or you could elect to use LINQ extension methods as opposed to Find in List<>

    Invoice inv = Invs.OfType<Invoice>().FirstOrDefault<Invoice>(someInv => someInv.SubInvoiceNumber == thePO.SubPONumber);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of code that looks like this: text = reg.Replace(text, new
I have a bit of code that I would like to see revision history
I have a bit of .NET code that retrieves the results from an Oracle
I have a bit of code that basically reads an XML document using the
I have a bit of code that passes around a ton of objects and
Well, I have this bit of code that is slowing down the program hugely
I have a bit of code for a dll that is needed by two
I have the following bit of legacy C++ code that does not compile: #include
I have an executable that defaults to 32-bit. It doesn't have source code and
I have an application that I've been tasked with cleaning up after. The application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.