static void Main(string[] args) { UpOn myUp = new UpOn(); UpOnHandler myIncDelegate = new UpOnHandler(myUp.Increment); int incrResult = myIncDelegate.Invoke(2); Console.WriteLine("Increment result: {0}", incrResult); UpOnHandler myDecDelegate = myUp.Decrement; int decResult = myDecDelegate(2); Console.WriteLine("Decrement result: {0}", decResult); Console.ReadLine(); }
static void Main(string[] args) { UpOn myUp = new UpOn(); UpOnHandler myIncDelegate = new UpOnHandler(myUp.Increment); UpOnHandler myDecDelegate = myUp.Decrement; Console.WriteLine("Multicasting..."); var myDelegate = myIncDelegate; int m = myIncDelegate(1); myDelegate += myDecDelegate; m = myDelegate(5); myDelegate -= myDecDelegate; m = myDelegate(1); Console.ReadLine(); }