Here is the simple tutorial for understanding C# Event and Delegate, I believe the code explain by itself:
using System; namespace EventDelegate2 { delegate void MyDelegate(); class Program { static event MyDelegate myEvent; static void Main(string[] args) { myEvent += new MyDelegate(Sing); myEvent += new MyDelegate(Dance); myEvent.Invoke(); } static void Sing() { Console.WriteLine("Sing"); } static void Dance() { Console.WriteLine("Dance"); } } } |
Here is the output:
No comments:
Post a Comment