![委托 匿名 lambda表达式 委托 匿名 lambda表达式](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
#region 委托
delegate int ACT(int a, int b);
static void Main(string[] args)
{
ACT act = new ACT(add);
int i = add(, );
Console.WriteLine(i);
Console.ReadKey();
}
public static int add(int a, int b)
{
return a + b;
}
#endregion #region 匿名
delegate int ACT(int a, int b);
static void Main()
{
ACT act = delegate (int num1, int num2)
{
return num1 + num2;
};
int he = act(, );
Console.WriteLine(he);
Console.ReadKey();
}
#endregion #region Lambda表达式
delegate int ACT(int a, int b);
static void Main()
{
ACT act = (a, b) => a + b;
int he = act(, );
Console.WriteLine(he);
Console.ReadKey();
}
#endregion