MyDelegate d = new MyDelegate(MyClass.Square);
d += new MyDelegate(MyClass.Cube);
d += new MyDelegate(MyClass.Double);
ExecuteMethod(d, 2);
static void ExecuteMethod(MyDelegate d, float x)
{
d(x);
}
delegate void MyDelegate(float x);
class MyClass
{
public static void Square(float x)
{
float result = x * x;
Console.WriteLine("{0}的平方等于:{1}", x, result);
}
public static void Cube(float x)
{
float result = x * x * x;
Console.WriteLine("{0}的立方等于:{1}", x, result);
}
public static void Double(float x)
{
float result = 2 * x;
Console.WriteLine("{0}的倍数等于:{1}", x, result);
}
}
网友评论