What’s the difference between anonymous methods (C# 2.0) and lambda expressions (C# 3.0)? [duplicate]

  1. Lambda expressions can be converted to delegates or expression trees (with some restrictions); anonymous methods can only be converted to delegates
  2. Lambda expressions allow type inference on parameters:
  3. Lambda expressions allow the body to be truncated to just an expression (to return a value) or single statement (in other cases) without braces.
  4. Lambda expressions allow the parameter list to be shortened to just the parameter name when the type can be inferred and when there’s only a single parameter
  5. Anonymous methods allow the parameter list to be omitted entirely when it’s not used within the body and it doesn’t lead to ambiguity

The last point is the only benefit of anonymous methods over lambdas, I believe. It’s useful to create a field-like event with a no-op subscription though:

public event EventHandler Click = delegate{};

Leave a Comment