219k views
5 votes
Create a Delegate to Compare two Integers.

1 Answer

5 votes

Answer:

Delegate is a function pointer which points the address of a function.

Step-by-step explanation:

Let the function to compare two integers takes two integers as arguments

C#.net syntax:

delegate void Del(int,int);

Here delegate is the keyword. Del is the name of the delegate which stores the address of the function whose return type is void and which takes 2 integer arguments.

public void CompareIntegers(int x, int y)

{

if (x>y) Console.WriteLine("X is greater");

else Console.WriteLine("Y is greater");

}

delegate void Del(int,int);

void main(){

Del del1=new Del(CompareIntegers);

}

User Dukeking
by
5.5k points