Using system;
Using system. Collections. Generic;
Using system. text;
Namespace consoleapplication8
{
// Define the delegate
Public Delegate bool comparedelegate (int A, int B );
Public class mycompare
{
/// <Summary>
/// Define a method that meets the requirements of the delegate defined above. The return value is bool type and the two parameters are int type respectively.
/// </Summary>
/// <Param name = "X"> </param>
/// <Param name = "Y"> </param>
/// <Returns> </returns>
Public static bool comparemethod (int x, int y)
{
Bool result = x> Y? True: false;
Return result;
}
}
Class Program
{
Static void main (string [] ARGs)
{
// Instantiate the delegate and initialize it. Note that a method name must be included during initialization, and the method must comply with the signature (parameter type and return value) when the delegate is initially defined)
Comparedelegate mydelegate = new comparedelegate (mycompare. comparemethod );
// Now we use a delegated instance to compare the size of two numbers A and B
Int A = 10;
Int B = 15;
Bool isbigger = mydelegate (A, B );
Console. writeline ("A> B? : "+ Isbigger );
Console. Read ();
}
}
}