
An anonymous function has no name. This kind of C# function offers more flexibility than a lambda expression. By using the delegate keyword, you can add multiple statements inside your anonymous function. It can use if-statements and loops.
This C# article demonstrates the syntax for anonymous functions.

First, this example uses the FindAll method on the List type, which requires a delegate instance that receives one integer and returns a boolean. The argument to FindAll here demonstrates the anonymous method syntax. We validate the argument using two if-statements; this cannot be done using a lambda expression. Finally, a boolean expression is evaluated and returned.
Program that uses anonymous method [C#]
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<int> values = new List<int>() { 1, 1, 1, 2, 3 };
// This syntax enables you to embed multiple statements in an anonymous function.
List<int> res = values.FindAll(delegate(int element)
{
if (element > 10)
{
throw new ArgumentException("element");
}
if (element == 8)
{
throw new ArgumentException("element");
}
return element > 1;
});
// Results.
foreach (int val in res)
{
Console.WriteLine(val);
}
}
}
Output
2
3
What about lambda expressions? It is possible to use lambda expressions in this context—even preferable. To see examples of lambda expressions on the FindAll method, please visit the relevant article on this website.
List Find Method Lambda Expression
The best resource for the syntax of the C# language is the C# Specification. The annotated third edition presents section 7.14, which describes the syntax here in detail, with excellent comments by Don Box and Bill Wagner.
The C# Programming Language: Specification
There are several syntaxes available for higher-order functions in the C# language. Typically, the lambda expression syntax is clearest, but the syntax shown here can provide more powerful method bodies because it allows multiple statements.
Delegate Tutorial