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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:47:51+00:00 2026-05-31T04:47:51+00:00

I often hear developers say C# functions are very powerful. Having heard this so

  • 0

I often hear developers say C# functions are very powerful. Having heard this so often I believe it is true but having not used functions too often I still don’t understand where their power lies. I have two questions:

1) What is the true power of C# functions, where can they be applied?

2) Aren’t normal methods the same as functions, for example what is the difference with the two below:

public int GetNumberOfDays(int randomVariable);

and

Func<int,int> 
  • 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-31T04:47:52+00:00Added an answer on May 31, 2026 at 4:47 am

    Func<int, int> is a delegate type that represents a method that takes one parameter of type int and returns an int. Delegates are powerful: they allow you to pass one or more functions to another function. Delegates have other powers as well, but I will ignore them for this discussion.

    Passing a function to another function is a key concept with Linq to Objects:

    int TimesTwo(int arg) { return arg * 2; }
    
    int TimesThree(int arg) { return arg * 3; }
    
    IEnumerable<int> DoubleTheSequence(IEnumerable<int> input)
    {
        return input.Select(TimesTwo);
    }
    
    IEnumerable<int> TripleTheSequence(IEnumerable<int> input)
    {
        return input.Select(TimesThree);
    }
    

    In this case, we are using the Select method, which takes a sequence and a function and returns the sequence that results from applying the function to each member of the input sequence.

    In the example above, TimesTwo and TimesThree are passed to the Select method by virtue of “implicit method group conversion”. In short, the compiler converts the bare method name to a delegate that refers to the correct overload of the method. The term is “method group” because when a method is overloaded, the name refers to all of the overloads as a group, and the compiler must choose the correct overload.

    It can be inconvenient to write several methods simply because we want to pass them to other methods. That’s why C# introduced anonymous delegates and, later, the more concise lambda expression. Now, suppose we want to be able to quadruple our sequence in addition to doubling or tripling it. Instead of writing a new function called TimesFour, we can use a lambda:

    IEnumerable<int> QuadrupleTheSequence(IEnumerable<int> input)
    {
        return input.Select(i => i * 4);
    }
    

    Finally, we could make a more generic TransformTheSequenceInSomeArbitraryManner method:

    IEnumerable<int> TransformTheSequenceInSomeArbitraryManner(IEnumerable<int> input, Func<int, int> f)
    {
        return input.Select(f);
    }
    

    That example is obviously just a trivial wrapper around the Select method, but it serves to illustrate how you would declare a method that takes a Func<int, int> parameter. This method shows two ways of using that parameter:

    int CallTheFunctionTwice(int input, Func<int, int> f)
    {
        int intermediateValue = f.Invoke(input);
        int result = f(intermediateValue);
        return result;
    }
    

    Specifically, you can invoke a delegate either by calling its Invoke method explicitly, or with method-call syntax. The compiled code is identical for either approach.

    Finally, to answer your question:

    What is the difference between public int GetNumberOfDays(int randomVariable) and Func<int,int>?

    The first is a method declaration; it declares a specific method that takes an int argument and returns a specific int whose value presumably depends on the value of the argument. The second is a delegate type that can hold a reference to any method with the same signature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often hear/read about interfaced based programming but I am not exactly clear on
I often hear people say to use $_SERVER['SERVER_ADDR'] , but that returns the LAN
I believe this is not the popular stance but I prefer embedded hacks such
I often hear around here from test driven development people that having a function
What are the top 5-10 most often used jQuery native API functions? (please do
I often hear people bashing ORMs for being inflexible and a leaky abstraction, but
Assembly is a language I'd like to learn but still you don't hear often
I often hear the terms 'statically linked' and 'dynamically linked', often in reference to
I often hear things like Can we load our employee info using LDAP? Yet,
I often hear complaints that programming languages that make heavy use of symbols for

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.