example -1
class Program
{
public delegate void Print(int value);
static void Main(string[] args)
{
Print print = delegate(int val)
{
Console.WriteLine("Inside Anonymous method. Value: {0}", val);
};
print(100);
print(2000);
Console.ReadLine();
}
}
example -2
class Program
{
public delegate void Print(int value);
static void Main(string[] args)
{
int i = 10;
Print prnt = delegate(int val)
{
// val += i;
val = val + i;
Console.WriteLine("Anonymous method: {0}", val);
};
prnt(100);
Console.ReadLine();
}
}
example -3
class Program
{
public delegate void Print(int value);
static void Main(string[] args)
{
PrintHelperMethod(delegate(int val)
{
Console.WriteLine("Anonymous method: {0}", val);
}, 100);
Console.ReadLine();
}
public static void PrintHelperMethod(Print printDel, int val)
{
val += 10;
printDel(val);
}
}