Func<int, int> add1 = i => i + 1;
Func<int, int, int> add = (i, j) => i + j;
// Behaviourally equivalent to:
int Add1(int i)
{
return i + 1;
}
int Add(int i, int j)
{
return i + j;
}
...
Console.WriteLine(add1(42)); //43
Console.WriteLine(Add1(42));...
See remarks for discussion of closures. Suppose we have an interface:
public interface IMachine<TState, TInput>
{
TState State { get; }
public void Input(TInput input);
}
and then the following is executed:
IMachine<int, int> machine = ...;
Func<int, int> machineC...
Expression<Func<int, bool>> checkEvenExpression = i => i%2 == 0;
// lambda expression is automatically converted to an Expression<Func<int, bool>>