Why can’t c# use inline anonymous lambdas or delegates? [duplicate]

Lambdas in C# do not have types, until they are used in a context that casts them to a delegate or Expression type.

That’s why you cannot do the following:

var x = () => "some lambda";

You might enjoy Eric Lippert’s Series on Lambda Expressions vs Anonymous Methods

  • Lambda vs Anon – Part One
  • Lambda vs Anon – Part Two
  • Lambda vs Anon – Part Three
  • Lambda vs Anon – Part Four
  • Lambda vs Anon – Part Five

Leave a Comment

tech