C#的委托案例
程序员文章站
2022-06-05 17:21:25
C#实现(Delegate)的委托就不多说了,直接上代码,看代码中的注释: namespace Delegate { delegate void DGSayiHi(string name);//声明委托 delegate void DGDo(string name); class Program { ......
c#实现(delegate)的委托就不多说了,直接上代码,看代码中的注释:
namespace delegate { delegate void dgsayihi(string name);//声明委托 delegate void dgdo(string name); class program { static void main(string[] args) { dgsayihi sayhi = new dgsayihi(saychinesehi); dgsayihi sayhi2 = new dgsayihi(sayenglishhi); sayhi += sayhi2;//实际上+=相当于delegate.combine, -=相当于delegate.remove sayhi("春晓"); console.readline(); } static void saychinesehi(string name) { console.writeline("你好:" + name); } static void sayenglishhi(string name) { console.writeline("hello:" + name); } } }
上一篇: Python活力练习Day1