Understanding Anonymous method in C#
An anonymous function is an "inline" statement or expression that can be used wherever a delegate type is expected. You can use it to initialize a named delegate or pass it instead of a named delegate type as a method parameter.
You can use a lambda expression or an anonymous method to create an anonymous function. We recommend using lambda expressions as they provide more concise and expressive way to write inline code.
Anonymous methods are the methods without a name, just the body.
delegate void CheckNumber(int n); // below is Anonymous body [without name] CheckNumber cn = delegate(int x) { Console.WriteLine("Anonymous Method: {0}", x); };
The delegate could be called both with anonymous methods as well as named methods in the same way, i.e., by passing the method parameters to the delegate object.
cn(10);