Delegate in C#


A delegate is the representative of a class. The main feature or quality of Delegate is that it can call any method of a class. To use Delegate in C#, you have to give the signatures of the delegate using delegate keyword.

Delegate int Transformer (This line shows that Transformer is a delegate of class, and the return type of this class is int. Inside the bracket of this instance, there is int x which shows that this instance will deal with variable x of type int(integer).


In the very beginning of the class, type a line which will show that delegate is implemented in this class:


Now the class is Program which is the name of the project and Transformer is the delegate of this class.

Now the code inside Program class will look like this:


Delegate as transformer:

Calculate Sum, Product, and Remainder using Delegate in C#

Suppose you want the user to enter a number on which the functions of Square(), Add() & RemainderTwo() will have to be applied in this case the code will look like this:


Leave a Reply

Your email address will not be published. Required fields are marked *