Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of "()=>" [duplicate]

Tags:

c#

I haven't really come across this syntax during my Programming classes in Uni before and I'm curious as to what it means.

The only times I've had to implement it was:

  1. When I had to create a BackgroundWorker that had to be added to the ProgressChanged event

    Invoke((MethodInvoker)(() => updatePing((int) e.UserState)));

  2. When researching tutorials on using the Caliburn.Micro MVVM framework

    NotifyOfPropertyChange(() => Count);

I have tried searching around on what this notation means but the special characters it uses seem to mess with google search and I have no idea what it is called.

like image 613
clifford.duke Avatar asked May 15 '13 17:05

clifford.duke


People also ask

Whats the meaning of duplicated?

/ˈduː.plə.keɪt/ to make an exact copy of something: The documents had been duplicated. Parenthood is an experience nothing else can duplicate.

What does it mean to do something in duplicate?

idiom. 1. : so that there are two copies. We were required to fill out the paperwork in duplicate. : with an exact copy.


1 Answers

The => is syntax for a lambda expression.

The () signifies that there are no parameters - if there were parameters and the types could be inferred from context, they could be specified as something like this:

(x, y) => x + y

Or specifying the types explicitly

(int x, string y) => x + y.Length

If there's only one parameter and its type can be inferred, you don't need the brackets:

x => x.Length
like image 64
Jon Skeet Avatar answered Sep 29 '22 20:09

Jon Skeet