5

Possible Duplicates:
Lamda Explanation and what it is as well as a good example
What is the => token called?

I have seen this code:

myContext.SomeEntities.Single(x => x.code == code);  

And I don´t know what does the => operator do.

Every search on google about the operator returns no results.

Thank you.

Community
  • 1
  • 1
Javiere
  • 1,601
  • 1
  • 13
  • 28
  • similar: http://stackoverflow.com/questions/5873603/whats-the-point-of-a-lambda-expression –  Jun 21 '11 at 17:16
  • http://stackoverflow.com/questions/274022/how-do-i-pronounce-as-used-in-lambda-expressions-in-net – Bob G Jun 21 '11 at 17:17
  • @Steve: Is that even a duplicate? That user in your question knows what a lambda expression is, @Javiere does not. He is asking what => does much like someone would ask what the ! sign does. –  Jun 21 '11 at 17:17
  • 1
    google can't handle searching for `=>` search for lambda instead. – Nix Jun 21 '11 at 17:18
  • @0A0D - I dunno, that q seemed to cover the required ground to me. Syntax and semantics. – Steve Townsend Jun 21 '11 at 17:32

5 Answers5

15

The => operator designates a Lambda Expression:

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

static void Main(string[] args)
{
    Func<int, int> func = x => x * x;
    int j = func(5);
    // j == 25
}
Community
  • 1
  • 1
dtb
  • 213,145
  • 36
  • 401
  • 431
2

Lambda expressions, very cool.

http://msdn.microsoft.com/en-us/library/bb397687.aspx

Dean Thomas
  • 1,096
  • 1
  • 10
  • 25
2

It signals that the code is a lambda expression.

More info: http://msdn.microsoft.com/en-us/library/bb397687.aspx

Harry
  • 61
  • 1
  • 15
Jeff
  • 5,913
  • 2
  • 28
  • 30
2

This is defining a lambda. You can read it "x goes to x.code equals code," and it means that given x, return the result of the given comparison.

David Ruttka
  • 14,269
  • 2
  • 44
  • 39
1

They are related to lambda expressions.

You can read about Lambda Expressions here: http://www.rvenables.com/2009/03/practical-introduction-to-lambda-expressions/

jessegavin
  • 74,067
  • 28
  • 136
  • 164