标签:UNC vat show 委托 ide return new oid 签名
注册绑定多个具有相同签名的方法,在一个委托上,
Func有返回值的内置委托,有17个重载方法
Action无返回值的内置委托,有16个重载方法
事件与委托必须具有相同方法的签名
委托是一个不能被继承的密封类且可以将方法当做参数传递的引用类型
如下:
/// <summary>
/// 多播委托
/// </summary>
public class MultiDelegate
{
private delegate int DemoMultiDelegate(out int x);
private static int Show1(out int x)
{
x = 1;
Console.WriteLine("This is the first show method:"+x);
return x;
}
private static int Show2(out int x)
{
x = 2;
Console.WriteLine("This is the second show method:"+x);
return x;
}
private static int Show3(out int x)
{
x = 3;
Console.WriteLine("This is the third show method:"+x);
return x;
}
/// <summary>
/// 调用多播委托
/// </summary>
public void Show()
{
DemoMultiDelegate dmd = new DemoMultiDelegate(Show1);
dmd += new DemoMultiDelegate(Show2);
dmd += new DemoMultiDelegate(Show3);//检查结果
int x = 5;
int y= dmd(out x);
Console.WriteLine(y);
}
}
/*----------------------多播委托---------------------------------*/ MultiDelegate multiDelegate = new MultiDelegate(); multiDelegate.Show();
标签:UNC vat show 委托 ide return new oid 签名
原文地址:https://www.cnblogs.com/Culley/p/11323526.html