Delegate vs Lambda function

Arsium ***** 331 Reputation points
2021-07-11T19:17:14.793+00:00

Hello ,

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

 Task.Run(delegate () 
                {

                });

and

  Task.Run(() =>
                {

                });
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-07-11T19:45:52.543+00:00

    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://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#anonymous-function-expressions].

    The old form with ‘delegate’ seems rarely used.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Arsium ***** 331 Reputation points
    2021-07-12T10:37:04.217+00:00

    Really clear answer ! Thx you !

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.