Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>They <em>do</em> the same thing but the "() => ..." syntax is what is called a lambda expression and as such is the same as an anonymous function. You could probably leave out the delegate part altogether and just let the compiler infer the delegate type for you.</p> <pre><code>del = this.SomeAction; </code></pre> <p>Depending on what type "del" is seclared as.</p> <p><strong>Edit</strong></p> <p>Using lambdas or anonymous methods or just a regular method for starters enables you to map methods that didn't have the delegate's signature to the delegate.</p> <p>For example, say you have a delegate with the signature bool myDelegate(int, int) but you wanted to have a method with the signature bool myMethod(string, string) handle the delegate. You could then use the lambda expression to let you do this inline with a short syntax like so.</p> <pre><code>delegate bool myDelegate(int x, int y); // With lambdas... myDelegate del = (int a, int b) =&gt; myMethod(a.ToString(), b.ToString()); // With anonymous methods... myDelegate del2 = delegate(int a, int b) { return myMethod(a.ToString(), b.ToString()); }; // The good ol' way without lambdas or anonymous methods... myDelegate del3 = SomeDelegateHandler; ... then write a method somewhere else ... // Handler method private bool SomeDelegateHandler(int a, int b) { return myMethod(a.ToString(), b.ToString()); } </code></pre> <p>So as you can see lambdas and anonymous methods are basically just a shorter/inline way of making a method to handle the delegate. In you case you might not need to make an extra method. It just depends on if the delegate signature is the same as your method signature, and to me, it seems like it is.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload