C# 委托数组.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{ ///
///定义两个操作方法
///
class MathOperations
{
public static double MultilyByx2(double value)
{
return value * 2;
}
public static double Square(double value)
{
return value * value;
}
}
///
/// 定义委托
///
///
///
delegate double DoubleOp(double value);
class Program
{
///
/// 委托数组
///
///
static void Main(string[] args)
{
DoubleOp[] operations =
{
new DoubleOp(MathOperations.MultilyByx2),
new DoubleOp(MathOperations.Square)
};
for (int i = 0; i
/// 方法
///
///
///
static void ProcessDisplayNum(DoubleOp Action, double value)
{
Console.WriteLine("初始值是:{0}操作数结果是{1}", value, Action(value));
}
}
}