C#(委托a) public delegate double TheOperator(double x, double y); public class Operators { static public double Add(double x, double y) { return x + y; } static public double Sub(double x, double y) { return x - y; } //乘,除法 我也懒得废话了 } public class DotNet_Calculator { public double Foo(TheOperator op, double x, double y) { return op(x, y); } } public class TheMainClass { static public void Main() { TheOperator myAdd = new TheOperator(Operators.Add); TheOperator mySub = new TheOperator(Operators.Sub); DotNet_Calculator dc = new DotNet_Calculator(); double sum = dc.Foo(myAdd, 2, 4); //sum = 6 System.Console.WriteLine(sum); double sub = dc.Foo(mySub, 3, 7); //sub = -4 System.Console.WriteLine(sub); } } C#(委托b) //小张类 public class MrZhang { //其实买车票的悲情人物是小张 public static void BuyTicket() { Console.WriteLine("NND,每次都让我去买票,鸡人呀!"); } } //小明类 class MrMing { //声明一个委托,其实就是个“命令” public delegate void BugTicketEventHandler(); public static void Main(string[] args) { //这里就是具体阐述这个命令是干什么的,本例是MrZhang.BuyTicket“小张买车票” BugTicketEventHandler myDelegate = new BugTicketEventHandler(MrZhang.BuyTicket); //这时候委托被附上了具体的方法 myDelegate(); Console.ReadKey(); } }