// Error! Method does not match delegate pattern!
BinaryOp b2 = new BinaryOp(SimpleMath.SquareNumber);
Investigating a Delegate Object
Let’s spice up the current example by creating a static method (named DisplayDelegateInfo())
within the Program type. This method will print out names of the methods maintained by the
incoming delegate type as well as the name of the class defining the method. To do so, we will iter-
ate over the System.Delegate array returned by GetInvocationList(), invoking each object’s Target
and Method properties:
static void DisplayDelegateInfo(Delegate delObj)
{
Do'stlaringiz bilan baham: |