C# is a programming language that was designed for building enterprise applications that run on the .Net framework. It evolves from Microsoft C and Microsoft C++. This is simple, modern and object oriented software. The C# Compiler is defined as the generator that seals class with four virtual methods. C# Delegate is an object that has been created to refer to a static method or an instance method. A web client can develop a new C# Delegate type. When defining a new class, normally the class keyword identifier, followed by implementation method, properties and fields are the standard practices that are taken into account. The case is different with C# delegates. When defining a new delegate type, the C# compiler generates the class called “Delegate to Method” – it drives the system.
The C# Compiler generates the sealed class with four virtual methods where the procedures are implemented by the Common Language Runtime. Microsoft has saved the programmer lot of time by providing the delegate keyword which can be used by them to generate a class, based on this system. The web client can foresee a delegate as a type-safe function pointer implying that the parameter lists as well as the return types are known factors. Creating a delegate object with the new operator is feasible and once the method has been conveyed, it can be encapsulated. Since the conveyed methods are static, the first parameter would have a null value.
To utilize a C# delegate, the following guidelines are considered:
01) Defining a new type that inherits from the system. Multicast delegate class provides the signature of the method that can be encapsulated by the new type.
02) Creating an instance or static method with the same signature as defined by the new delegate type.
03) Developing a new delegate object using the new operator and conveying the method as a parameter.
04) “Invoke” the delegate object and call for the reference method.
The delegate type automatically inherits the system which provides the functionality to create a chain of delegate through a linked list. A multi cast delegate is an object that maintains the linked list of delegates. The method “Combine” is used to create multi cast delegates. When the software is loaded along with the application of ILDASN, the utility of this method becomes more apparent. The “call-back” method illustrates the usefulness of delegates. It provides a great functionality that demonstrates the delegation of a task to another object. For example, in the case of three classes – Employee, Department and System – the Department class delegates the task of updating the Employees’ salaries to the System class through the use of “call-back” method. The implementation of this method is very simple.
“Call-back” method introduces the manner of conducting conversation between two objects. This implies that the Department object is delegating the function of updating the Employees’ salaries to the class system through a “call-back’ method. To utilize the “call-back” method, one needs to create a delegate and a method which accepts the delegate as a parameter. Delegates are the technology that implements a “type-safe” method of “call-back” mechanism. This could be used effectively by many parts of the .Net framework including Windows forum and ASP .Net Web form and others.