Home > Articles > Programming > C#

Anonymous Methods in C# 2.0

  • Print
  • + Share This
While demonstrating the rudiments of anonymous methods, Paul Kimmel answers the question "Are anonymous methods just someone being a bit too clever?"
This article is adapted from Paul's book C# Express (Addison-Wesley).
Like this article? We recommend


All methods use a subset of elements from the same master set. In C# 2.0, the set of optional elements will grow. Historically—except in C++ inline methods—methods required a name, a return type, and a body. Optionally, methods could use an access modifier and a parameter list. In C# 2.0, the method name has been moved from the list of required items to the list of optional items.

C# 2.0 (and .NET in general) introduces the anonymous method. An anonymous method can be used anywhere a delegate is used and is defined inline, without a method name, with optional parameters and a method body.

To use anonymous methods, you need to know what a delegate is, so we'll review delegates briefly before getting into when to use anonymous methods and about anonymous method limitations.

  • + Share This
  • 🔖 Save To Your Account