Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




What is Event - Delegate? clear syntax for writing a event delegate

The event keyword lets you specify a delegate that will be called upon the occurrence of some "event" in your code. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. An event in one program can be made available to other programs that target the .NET Framework Common Language Runtime.

// keyword_delegate.cs
// delegate declaration
delegate void MyDelegate(int i);
	class Program
	{
	   public static void Main()
	   {
	      TakesADelegate(new MyDelegate(DelegateFunction));
	   }
	   public static void TakesADelegate(MyDelegate SomeFunction)
	   {
	      SomeFunction(21);
	   }
	   public static void DelegateFunction(int i)
	   {
 	      System.Console.WriteLine("Called by delegate with number: {0}.", i);
 	   }
}

Share this article   |    Print    |    Article read by 1443 times
Author:
Guest
Guest user is that user who have done some activity on website without login. Activity contains commenting on any article, uploading an image on website etc.
Related Articles: No related article
Related Interview Questions: