After running, we will analyze the following results:
Class chaplain
{
Public static gold coin MinisterAOneYearDo ()
{
Gold coin = new gold coin (100);
Console. WriteLine ("I am Minister A, and I have brought 100 gold coins to the king." );
Return coins;
}
}
Class pastor b
{
Public static goods department
{
Commodity commodity = new goods ();
Console. WriteLine ("I'm Minister B, and I've brought the king exquisite goods that are not available in our country." );
Return goods;
}
}
Class teacher c
{
Public static gold coin MinisterCOneYearDo ()
{
Gold coin = new gold coin (10);
Console. WriteLine ("I am Minister C, and I brought the same 10 gold coin to the king." );
Return coins;
}
}
Class plan
{
Static void Main(string[] args)
{
//Let's learn about the king's decree, which is actually our entrusted signature.
//delegate MinisterReturns ministeroneyardo();
Console. WriteLine ("the king's order:", the king. KingsOrder);
//Minister A passes the method written according to the proxy signature to another method for processing.
king . handleministeroneyardo(MinisterA。 ministeroaneyeardo);
Console. ReadLine();
//Minister B passes the method written according to the proxy signature to another method for processing.
king . handleministeroneyardo(MinisterB。 MinisterBOneYearDo);
Console. ReadLine();
//Minister C passes the method written according to the proxy signature to another method for processing.
king . handleministeroneyardo(MinisterC。 ministerconyeardo);
Console. ReadLine();
}
} It has been said above why the value returned by the concrete implementation method is different from that returned by the delegate delegate. In fact, covariation is used in delegation. The following is a reference to the covariant analysis represented by MSDN. When the return type of a delegate method is more derived than the delegate signature, it is called a covariant delegate method. Because the return type of a method is more specific than that of a delegate signature, it can be implicitly converted. This method can then be used as a delegate. Covariance makes it possible to create delegate methods that can be used by both classes and derived classes.