1. lambda
example 1
// Create a basic delegate that squares a number
MyDelegate foo = (x) => x * x;
Console.WriteLine("The result of foo is: {0}", foo()); // Dynamically change the delegate to something else
foo = (x) => x * ;
Console.WriteLine("The result of bar is: {0}", foo());
example 2
// Create a delegate that takes multiple arguments
MyDelegate2 bar = (x, y) =>
{
Console.WriteLine("The two-arg lambda: {1}, {0}", x * , y);
};
bar(, "Some string"); // Define an expression delegate
ExprDelegate baz = (x) => x > ;
Console.WriteLine("Calling baz with 5: {0}", baz());
Console.WriteLine("Calling bax with 15: {0}", baz());