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");
}
}
이 프로그램은 인쇄 C#을 위임 인스턴스화
Jon says: Hello
Tom says: Hello
대신
Tom says: Hello
이 제거가 작동하지 않습니다
:p -= jonsVoice;
왜?
다른 대표와 대리인의 인스턴스화에 대해 설명하거나 유용한 링크를 제공해 주시겠습니까? 비밀 정보에 관심이 있어요. 당신은 + = 연산자를 사용하여 대표를 결합하면
감사합니다. 이제는 이해할 수 있어요. – Realeyes