[ACCEPTED]-What does the C# operator => mean?-operators

Accepted answer
Score: 15

It's not really an operator as such, it's 17 part of the syntax for lambda expressions. In 16 particular => is the bit which separates 15 the parameters from the body of the lambda 14 expression.

Does your book cover C# 3.0? If 13 not, it won't include lambda expressions. If 12 it does, it should really cover them! Hopefully 11 with the right terminology, you'll be able 10 to find it in the TOC or index.

EDIT: A bit 9 more information: A lambda expression is 8 a piece of syntactic sugar to either create 7 an instance of a delegate or an expression 6 tree (the latter being new to .NET 3.5). Lambda 5 expressions almost entirely replace anonymous 4 methods (from C# 2.0) although they don't 3 support the notion of "I don't care about 2 the parameters" in the way that anonymous 1 methods do.

Score: 2

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

All lambda expressions use the 5 lambda operator =>, which is read as 4 "goes to". The left side of the 3 lambda operator specifies the input parameters 2 (if any) and the right side holds the expression 1 or statement block


Score: 2

The => token is called the lambda operator.

It is used 3 in lambda expressions to separate the input 2 variables on the left side from the lambda 1 body on the right side.


Score: 1

That will be for a lambda expression:


An 4 example is here:

MyControl.OnMouseDown += (sender, e) =>
  // Do something in the mouse down event

Here I have created a lambda 3 expression event delegate. It basically 2 saves me from having to create a separate 1 function for it in the class.

More Related questions