// http://w...content-available-to-author-only...t.com/Articles/11657/Understanding-Delegates-in-C
using System;
delegate void Delegate_Multicast(int x,int y);
class Class2
{
static void Method1(int x,int y)
{
Console.WriteLine ("You're in Method 1");
}
static void Method2(int x,int y)
{
Console.WriteLine ("You're in Method 2");
}
public static void Main(string[] args)
{
Delegate_Multicast func = new Delegate_Multicast(Method1);
func += new Delegate_Multicast(Method2);
func(1,2); // Method1 and Method2 are called
func -= new Delegate_Multicast(Method1);
func(2,3); // Only Method2 is called
}
}
Ly8gaHR0cDovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnQuY29tL0FydGljbGVzLzExNjU3L1VuZGVyc3RhbmRpbmctRGVsZWdhdGVzLWluLUMKdXNpbmcgU3lzdGVtOwpkZWxlZ2F0ZSB2b2lkIERlbGVnYXRlX011bHRpY2FzdChpbnQgeCxpbnQgeSk7CmNsYXNzIENsYXNzMgp7CglzdGF0aWMgdm9pZCBNZXRob2QxKGludCB4LGludCB5KQoJewoJCUNvbnNvbGUuV3JpdGVMaW5lICgiWW91J3JlIGluIE1ldGhvZCAxIik7Cgl9CgkKCXN0YXRpYyB2b2lkIE1ldGhvZDIoaW50IHgsaW50IHkpCgl7CgkJQ29uc29sZS5Xcml0ZUxpbmUgKCJZb3UncmUgaW4gTWV0aG9kIDIiKTsKCX0KCQoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oc3RyaW5nW10gYXJncykKCXsKCQlEZWxlZ2F0ZV9NdWx0aWNhc3QgZnVuYyA9IG5ldyBEZWxlZ2F0ZV9NdWx0aWNhc3QoTWV0aG9kMSk7CgkJZnVuYyArPSBuZXcgRGVsZWdhdGVfTXVsdGljYXN0KE1ldGhvZDIpOwoJCWZ1bmMoMSwyKTsJCQkJCQkJCQkvLyBNZXRob2QxIGFuZCBNZXRob2QyIGFyZSBjYWxsZWQKCQlmdW5jIC09IG5ldyBEZWxlZ2F0ZV9NdWx0aWNhc3QoTWV0aG9kMSk7CgkJZnVuYygyLDMpOwkJCQkJCQkJCS8vIE9ubHkgTWV0aG9kMiBpcyBjYWxsZWQKCX0KfQ==