using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 委托
{
class Program
{
staticvoid Main(string[] args)
{
//实例化委托
MyDel 基友B = new MyDel(sendLetter);
//实例调用=》指向委托方法 sendLe
基友B();
}
//定义一个委托事件 送情书publicstaticvoidsendLetter()
{
Console.WriteLine("**********************************");
Console.WriteLine("I love you 女神C");
Console.WriteLine("**********************************");
Console.ReadKey();
}
}
delegatevoid MyDel();
}
3)委托多播之礼物风波
A:基友B都三天过去了
B:耐心一点,心急吃不了热豆腐!
A:可是不会一点动静都没有吧
B:你想是不是你信中没表达清楚?
A: 怎么可能,哎呀,对了信上好象没有署名~~(>_<)~~
B: -> ->
A:看来还要再麻烦你啦,嘿嘿
于是A又重新写了一封情书,并且还给女神C准备了一份礼物,把信和礼物一起委托给B去转交给C。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 委托
{
class ds
{
publicstaticvoidMain(string[] args)
{
//实例化ds类
ds 屌丝A = new ds();
//实例化委托
MyDel 基友B = new MyDel(屌丝A.sendLetter);
基友B += 屌丝A.sendGift;
基友B("屌丝A");
}
//定义一个委托事件 送情书publicvoidsendLetter(string name)
{
Console.WriteLine("**********************************");
Console.WriteLine("I love you 女神C" );
Console.WriteLine(" 署名:"+name);
Console.WriteLine("**********************************");
}
//送礼物publicvoidsendGift(string name) {
Console.WriteLine(name+"的礼物是仙人掌");
Console.WriteLine("**********************************");
Console.ReadKey();
}
}
delegatevoid MyDel(string name);
}