In this blog I am trying to explain the concept of Delegate Class in C#.
It is represents a delegate (representative), which is a data structure that refers to a static method or to a class instance and an instance method of that class.
The Delegate class is the base class for delegate types. However, only the system and compilers can derive explicitly from the Delegate class or from the MulticastDelegate class. It is also not permissible to derive a new type from a delegate type. The Delegate class is not considered a delegate type; it is a class used to derive delegate types.
Code Description: -
1. Using System (include the System namespace).
2. Create MindstickSamplesDelegate class.
4. Declares a delegate for a method that takes in an int and returns a String.
5. Defines some methods to which the delegate can point.
7. Defines an instance method.
15. Defines a static method.
24. Create main method.
26. to 28. Creates one delegate for each method. For the instance method, an instance (mySC) must be supplied. For the static method, use the class name.
29. to 31. Invokes the delegates.