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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:58:01+00:00 2026-05-15T03:58:01+00:00

I’m new in C# and earlier I saw the lambda expression is like (params)

  • 0

I’m new in C# and earlier I saw the lambda expression is like

(params) => { expression; }

but in LINQ, I saw examples like

IEnumerable<string> customerFirstNames = customers.Select(cust => cust.FirstName);

No brackets.

(I actually mean both {} and () – regardless if we call them braces, parenthesis, or brackets.)

Are they the same or is there any difference?

Thanks a lot.

  • 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-15T03:58:01+00:00Added an answer on May 15, 2026 at 3:58 am

    The rules are:

    A lambda expression has the form

    ( modifier type parameter, modifier type parameter ...) => { statements }
    

    Let’s consider the left side first.

    The modifier can be ref, out or nothing at all.

    If there are no ref or out modifiers then all the types can be elided. If there are any ref or out modifiers then every parameter declaration must have a declared type. If any paramter has a declared type then every parameter must have a declared type. So you can elide the types provided that (1) there are no refs or outs, and (2) you elide all of them. Otherwise, you must provide all the types.

    If there is exactly one parameter and its type has been elided then the parentheses around the parameter list may optionally be elided also.

    That’s all the rules about parameter lists. The rules about the right side are:

    if the statement list consists of a single return statement with an expression:

    x => { return x + 1; }
    

    then the braces, return keyword and semicolon may be elided:

    x => x + 1
    

    furthermore, if the statement list consists of a single statement that is a statement expression:

    x => { x++; } // Not returning the value of x++; only useful for the side effects
    x => { new Y(x); } // weird! executing a ctor only for its side effects! But legal!
    x => { M(x); } // note, not returning the value of M(x) even if there is one.
    

    then it is also legal to elide the braces and semicolon:

    x => x++
    x => new Y(x)  
    x => M(x)
    

    Note that these now potentially mean something different to the reader! Before we were clearly discarding the return values; now the lambdas will be read as returning them.

    Note that this means it is legal to do this trick with void returning methods. This is actually legal:

    x => Console.WriteLine(x)
    

    Yuck. Don’t do that. If you mean

    x => { Console.WriteLine(x); } 
    

    then say that instead. The former looks too much like you are trying to say

    x => { return Console.WriteLine(x); }
    

    which of course would be illegal.

    • 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
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.