Wednesday, July 27, 2011

Delegate :C# ( Digging , Explain , Use it)

Overview

.NET provides one nice characteristic that is delegate. Delegate is an object or instance which can hold reference of any function OR which can bind function. Referenced function may be static or any class object’s function. This can hold more than one function references. This also provides callback method. Developer’s perspective Delegate is two type single cast and multicast.

Every delegate base class is System.MulticastDelegate. System.MulticastDelegate class is inheriting from delegate class. Both classes are abstract class.

.NET provide standard constructor as follows:

Constructor for MultiCastDelegate : protected MulticastDelegate(object target, string method);

Constructor for Delegate : protected Delegate(object target, string method);
Declare Delegate

Declaring of the delegation is quite tricky, because when we declare delegation. We inform the compiler which kind of function signature’s reference could be hold by this delegate. Let’s explain by following: Fig-1.0 

Look at FIG-1.0:

Fig-001.png

  1.     public is Access modifier .
  2.     delegate is keyword which indicates this is delegate type.
  3.     Return type of function signature.
  4.     Delegate class name. (Explain below).
  5.     Parameter of function signature.
  6.     Parameter of function signature


Read more: Codeproject
QR: Delegate_in_C___Expain.aspx

Posted via email from Jasper-Net