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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:12:01+00:00 2026-06-11T12:12:01+00:00

while deepening myself to more advanced features of C#, I came across some code,

  • 0

while deepening myself to more advanced features of C#, I came across some code, which I didn’t exactly know the difference of. It’s about these two lines:

Func<string, int> giveLength = (text => text.Length);

and

Func<string, int> giveLength = delegate(string text) { return text.Length; };

This can be used in the same way:

Console.WriteLine(giveLength("A random string."));

So basically.. What is the difference of these two lines? And are these lines compiling to the same CIL?

  • 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-11T12:12:02+00:00Added an answer on June 11, 2026 at 12:12 pm

    They’re the same, basically. They’re both anonymous functions in C# specification terminology.

    Lambda expressions are generally more concise, and can also be converted to expression trees, which are crucial for out-of-process LINQ.

    Anonymous methods allow you to drop the parameter list if you don’t care. For example:

    EventHandler handler = delegate { 
        Console.WriteLine("Sender and args don't matter");
    };
    

    Given how rarely the latter point is required, anonymous methods are becoming an endangered species in modern C#. Lambda expressions are much more common.

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

Sidebar

Related Questions

while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
While refactoring my code base I found a piece of code which I'd like
While debugging and keep pressing F5, if the source code does not exist, eclipse
While playing with standard library i've found a strange difference between python2 and python3.
I find myself having a lot of this in different methods in my code:
I am a Python newbie coming from a C++ background. While I know it's
Some native iPhone applications (like Clock) display different default images while loading depending on
I'm planning to write a Windows app to help myself with some exploratory testing
I have 2 processes which both access an sqlite3 database. While reading is not
While building a Rails app, I recently encountered a situation in which I want

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.