Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the operator '=>' mean in C#?

What does the '=>' in this statement signify?

del = new SomeDelegate(() => SomeAction());

Is the above declaration the same as this one?

del = new SomeDelegate(this.SomeAction);

Thanks.

like image 771
Krakerjak Avatar asked Feb 22 '09 03:02

Krakerjak


1 Answers

Basically it's specifying an anonymous function, that takes no parameters that calls SomeAction. So yes, they are functionally equivalent. Though not equal. Using the lambda is more equivalent to:

del = new SomeDelegate(this.CallSomeAction);

where CallSomeAction is defined as:

public void CallSomeAction()
{
    this.SomeAction();
}

Hope that helps!

like image 54
mletterle Avatar answered Sep 28 '22 22:09

mletterle