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 728921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:44:13+00:00 2026-05-14T06:44:13+00:00

I’ve been seing Func<> for sometime now, and I’ve manage to avoid it (for

  • 0

I’ve been seing Func<> for sometime now, and I’ve manage to avoid it (for now). But, now it looks like I can’t dodge it forever. For instance, I tried Dynamic Linq, but almost everything was in terms of Func<>. I’ve tried one of my book (C# 2008/Deitel&Deitel) and also MSDN but I’m not getting it yet. They all jump straight in the subject.

  1. What can be said (in few words) about Func<>
  2. Can I get some links on the web that can get me started on that matter?

Thanks for helping

  • 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-14T06:44:14+00:00Added an answer on May 14, 2026 at 6:44 am

    Func<> is a generic delegate – it is just very convenient to use, because you don’t have to create your own delegate for each argument/return type combination.
    Earlier, you had to write something like:

    public delegate long MyDelegate( int number );
    
    public void Method( IEnumerable<int> list, MyDelegate myDelegate )
    {
        foreach( var number in list )
        {
            myDelegate( number );
        }
    }
    

    You had to publish your delegate so that a user can call your method correctly. Especially when you need a bunch of different delegates you ended up publishing one for every argument list and return type.
    With Func<> you just write:

    public void Method( IEnumerable<int> list, Func<int, long> myDelegate )
    {
        foreach( var number in list )
        {
            myDelegate( number );
        }
    }
    

    It means the same as the first code example – Func<int, long> defines a delegate that takes one integer argument and returns a long value.

    Of course you can use longer parameter lists, too: Func<int, int, bool, long> will still return a long value while it takes two ints and a bool value. If you wish a delegate without return value you will have to use Action<>, which will have void as a return type.

    EDIT (by request): How to call the method in my example:

    For the caller, there is no difference between the solution with MyDelegate or Func<>. In both cases he has three options to call the method:

    Using a lambda notation (C# 3.0 required, probably the best solution for short methods):

    Method( myList, i => i * i );
    

    By using an anonymous method (C# 2.0 required):

    Method( myList, delegate( int i )
    {
        return i * i;
    } );
    

    Or by using a real method as an argument:

    Method( myList, Square );
    
    private static long Square( int number )
    {
        return number * number;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.