0
点赞
收藏
分享

微信扫一扫

多播委托

仲秋花似锦 2022-10-25 阅读 79


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 委托
{
public delegate void DelTest();
class Program
{
static void Main(string[] args)
{
//多播委托
//当调用多播委托时,它连续调用每个方法。在调用过程中,委托必须为同类型,
//返回类型一般为void,这样才能将委托的单个实例合并为一个多播委托。
//如果委托具有返回值或输出参数,它将返回最后调用的方法的返回值和参数
DelTest del = T1;
del();
Console.WriteLine();
del += T2;
del();
Console.WriteLine();
del -= T2;
del();
}
public static void T1()
{
Console.WriteLine("我是T1");
}
public static void T2()
{
Console.WriteLine("我是T2");
}
}
}


举报

相关推荐

0 条评论