C#委托实现匿名方法
// CalculateTax is a delegate that takes a double and returns a double public delegate double CalculateTax(double x); static void Main(string[] args) { CalculateTax stateDelegate = delegate(double x) { return x * 0.05; }; CalculateTax federalDelegate = delegate(double x) { if (x > 1000.0) return x * 0.02; else return 0.0; }; double amountOfPurchase = 12.99; Console.WriteLine("{0}", stateDelegate(amountOfPurchase)); Console.WriteLine("{0}", federalDelegate(amountOfPurchase)); Console.In.ReadLine(); }