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.
Syntax:-
Example:-
Syntax:-
delegate(argument)
{
}
Example:-
public delegate void Print(int value);
static void Main(string[] args)
{
int i = 10;
Print prnt = delegate(int val)
{
val += i;
Console.WriteLine("Anonymous method: {0}", val);
};
prnt(100);
}
No comments:
Post a Comment