C# – What Does the Operator ‘=>’ Mean?

c++delegateslambda

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.

Best Answer

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!