using System;
namespace InheritanceApplication
{
delegate void PrintFunction();
class Test
{
public void Print1()
{
Console.WriteLine("Print1--instance");
}
public static void Print2()
{
Console.WriteLine("Print2--static");
}
}
class Program
{
static void Main()
{
Test t = new Test();
PrintFunction pf;
pf = t.Print1;//这里的pf有何意义?为何不可以写成pf += t.Print1;
pf += Test.Print2; //这里为何不可以写成pf = Test.Print2;
pf += t.Print1;
pf += Test.Print2;
if (null != pf)
pf();
else
Console.WriteLine("Delegate is empty");
}
}
}
对委托中的疑惑不理解
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
threenewbee 2023-05-30 11:02关注pf += t.Print1; 这个叫做多播委托,也就是把多个方法挂在一个委托上
第一次只能用 =
之后才可以 += (当然也可以 = 那样把之前的冲掉了)本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用