Mega Code Archive
0194 Func, Action and lambda
lambda expression are often used with Func and Action delegates.
Func and Action are predefined delegates with generic parameters.
delegate TResult Func ();
delegate TResult Func (T arg);
delegate TResult Func (T1 arg1, T2 arg2);
... and so on, up to T16
delegate void Action ();
delegate void Action (T arg);
delegate void Action (T1 arg1, T2 arg2);
... and so on, up to T16
Here is an example of how use to use Func to create a lambda expression.
using System;
class Program
{
public static void Main()
{
Func sqr = x => x * x;
Console.WriteLine(sqr(3));
}
}
The output:
9