xxxxxxxxxx
/*
As the name suggests, an anonymous method is a method without a name.
Anonymous methods in C# can be defined using the delegate keyword
and can be assigned to a variable of delegate type.
*/
//For example, suppose we have a delegate that points to a void method with only one parameter.
delegate void Display(string msg);
static void Main(string[] args)
{
// Make a delegate instance that points to an anonymous method.
Display d2 = delegate(string msg) {
Console.WriteLine();
};
// this function has no name
// If your function contains a single statement, you can remove the delegate keyword, the datatype of the variable, and the curly braces.
/*
Display d2 = msg => Console.WriteLine(msg);
This is ( => ) known as a "fat arrow."
This syntax is called a lambda expression.
*/
Display d = msg => Console.WriteLine(msg);
}