question

Arsium-4135 avatar image
0 Votes"
Arsium-4135 asked Arsium-4135 answered

Delegate vs Lambda function

Hello ,

While learning delegates and lambda expressions, I was wondering what is the difference between :

  Task.Run(delegate () 
                 {
           
                 });

and

   Task.Run(() =>
                 {
    
                 });
dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
1 Vote"
Viorel-1 answered Viorel-1 edited

According to documentation, both represent “anonymous functions”, and, for historical reasons, “there are two syntactic flavours of anonymous functions, namely lambda_expressions and anonymous_method_expressions. For almost all purposes, lambda_expressions are more concise and expressive than anonymous_method_expressions, which remain in the language for backwards compatibility [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#anonymous-function-expressions].

The old form with ‘delegate’ seems rarely used.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Arsium-4135 avatar image
0 Votes"
Arsium-4135 answered

Really clear answer ! Thx you !

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.