lambda
In this chapter you will learn:
lambda expressions
lambda is an anonymous delegate instance. Suppose we have a delegate:
delegate int Calculate(int i);
We can create an lambda expression as follows:
Calculate c = x => x+1;
x
is the parameter and x+1
is the method body.
The following code puts everything together to show how to use lamda expression.
using System;/*j a v a 2 s . com*/
delegate int Calculate(int i);
class Program
{
public static void Main()
{
Calculate c = x => x + 1;
Console.WriteLine(c(1));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » delegate, lambda, event