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

  • SEARCH
  • Home
  • 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 8318581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:01:17+00:00 2026-06-08T22:01:17+00:00

If I’m using generics, like in this sample case, is there a way to

  • 0

If I’m using generics, like in this sample case, is there a way to shorten the syntax so I don’t have to repeatedly type “CompanyLookupData”?

Func<CompanyLookupData, CompanyLookupData, bool> DELCompareNonKeyFieldsCompany =
    new Func<CompanyLookupData, CompanyLookupData, bool> 
    (CompanyLookupData.HasIdenticalNonKeyFieldsTo);

I had tried to do Type t = typeof(CopmanyLookupData), and use t in all of the locations, but that doesn’t appear to work.

PS: while I’m open to a cleaner way of doing exactly what’s shown, I’m more interested in a way to make generics syntax more concise in general.

  • 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-06-08T22:01:20+00:00Added an answer on June 8, 2026 at 10:01 pm

    Yes, there are a few ways to achieve this:

    If the variable is a local variable you can use the var keyword:

    var DELCompareNonKeyFieldsCompany = new Func<CompanyLookupData, CompanyLookupData, bool>   (CompanyLookupData.HasIdenticalNonKeyFieldsTo);
    

    However, if DELCompareNonKeyFieldsCompany is a class variable (a field or a property) you can let the compiler infer some of it for you by converting from a method group to a Func:

    Func<CompanyLookupData, CompanyLookupData, bool> DELCompareNonKeyFieldsCompany = CompanyLookupData.HasIdenticalNonKeyFieldsTo;
    

    If this type is to be used often, you may wish to create your own delegate type:

    public delegate bool CompareCompanyNonKeyFields(CompanyLookupData, CompanyLookupData);
    

    And use it like so:

    CompareCompanyNonKeyFields DELCompareNonKeyFieldsCompany = CompanyLookupData.HasIdenticalNonKeyFieldsTo;
    

    Alternatively if the type is only to be used within the one class, you could also create an alias to the type with the using keyword (although, personally, I find that this hinders the readability of the code):

    using CompareCompanyNonKeyFields = System.Func<CompanyLookupData, CompanyLookupData, bool>;
    ...
     CompareCompanyNonKeyFields DELCompareNonKeyFieldsCompany = CompanyLookupData.HasIdenticalNonKeyFieldsTo;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have two tables with like below codes: Table: Accounts id | username |
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I know there's a lot of other questions out there that deal with this

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.