委托学习
private delegate int SaceDelegate(int x, int y);private static int Sace(int x, int y)
{
return x + y;
}
static void Main(string[] args)
{
//方法1:实例化委托,并计算绑定计算方法
SaceDelegate safe = new SaceDelegate(Sace);
Console.WriteLine(safe(2, 3));
//方法2:匿名实例化并绑定计算方法
SaceDelegate xxx = delegate(int x, int y) { return x + y; };
Console.WriteLine(xxx(2, 3));
//方法3:Lambda表达式委托
SaceDelegatexxy= (x,y) =>{return x+y;};
//方法4:Lambda表达式的另一种实现方法
SaceDelegate xyy = (int x, int y) => { return x + y; };
Console.WriteLine(xxy(2,3));
Console.WriteLine(xyy(2, 3));
Console.ReadKey();
}
页:
[1]