Sunday, September 30, 2007

Delegate

  • Delegate is type which holds the method(s) reference in an object.it is also reffered as a type safe function pointers
  • Advantages:.Encapsulating the method's call from caller, Effective use of Delegate improves the performance of application..used to call a method asynchronously

Declaration:

public delegate type_of_delegate delegate_name()

Example : public delegate int mydelegate(int delvar1,int delvar2)

Note:.you can use delegate without parameter or with parameter list.you should follow the same syntax as in the method (if you are reffering the method with two int parameters and int return type the delegate which you are declaring should be the same format.This is how it is reffered as type safe function pointer



Delegates are functional pointers.In C#, a delegate is a data structure that refers to either a static method, or an object and an instance method of its class. When you initialize a delegate, you initialize it with either a static method, or a class instance and an instance method. (
http://www.yoda.arachsys.com/csharp/csharp2/delegates.html)

No comments: