什么是委托?

委托是一种引用方法的类型。一旦为委托分配了方法,委托将于该方法具有完全相同的行为。委托方法的使用可以想其他任何方法一样,具有参数和返回值

delegate int ACT(int a, int b);
static void Main(string[] args)
{
ACT act = new ACT(add);
int i = add(5, 8);
Console.WriteLine(i);
Console.ReadKey();
}
public static int add(int a, int b)
{
return a + b;
}

多播委托通过+=,-=进行实现

猜你喜欢

转载自www.cnblogs.com/dujian123/p/10521898.html
今日推荐