CalculateTax是一个委托,给定一个double值并返回一个double值
// CalculateTax is a delegate that takes a double and returns a double public delegate double CalculateTax(double x); static public double StateTax(double x) { return x * 0.05; } static public double FederalTax(double x) { if (x > 1000.0) return x * 0.02; else return 0.0; } static void Main(string[] args) { CalculateTax stateDelegate = new CalculateTax(StateTax); CalculateTax federalDelegate = new CalculateTax(FederalTax); double amountOfPurchase = 12.99; Console.WriteLine("{0}", stateDelegate(amountOfPurchase)); Console.WriteLine("{0}", federalDelegate(amountOfPurchase)); Console.In.ReadLine(); }