class Program
{
delegate void StringProcessor(string input);
class Person
{
string name;
public Person(string name) { this.name = name; }
public void Say(string message)
{
Console.WriteLine("{0} says: {1}", name, message);
}
}
class Background
{
public static void Note(string note)
{
Console.WriteLine("({0})", note);
}
}
static void Main(string[] args)
{
Person jon = new Person("Jon");
Person tom = new Person("Tom");
StringProcessor jonsVoice, tomsVoice, background;
jonsVoice = new StringProcessor(jon.Say);
tomsVoice = new StringProcessor(tom.Say);
background = new StringProcessor(Background.Note);
StringProcessor p = new StringProcessor(jonsVoice);
p += tomsVoice;
p -= jonsVoice;
p("Hello");
}
}
该程序打印
Jon says: Hello
Tom says: Hello
代替
Tom says: Hello
此删除不起作用:p -= jonsVoice;
但为什么?
您能否澄清这一点或获得一些有关与另一个委托的委托实例化的有用链接。我对卧底信息很感兴趣。