Friday, September 11, 2015

DELEGATES

DELEGATES

C# delegates are similar to pointers to functions, in C or C++.
 A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class. 

For example, consider a delegate: 
public delegate int MyDelegate (string s); 
The preceding delegate can be used to reference any method that has a single stringparameter and returns an int type variable.
Syntax for delegate declaration is: 
delegate <return type> <delegate-name> <parameter list>



No comments:

Post a Comment