{
class Program
{ delegate void MyDel(); public void Print1()
{
Console.WriteLine("I am print 1");
} public void Print2() { Console.WriteLine("I am print 2"); }
static void Main(string[] args)
{
Program program = new Program(); MyDel myDe = program.Print1;
myDe += program.Print2; myDe(); Console.ReadKey(); }
}
} ------------------------------------------------ using System; namespace ConsoleApp1
{
class Program
{ delegate void MyDel(string mystring);//有参数的委托 public void Print1(string mystring)
{
Console.WriteLine(mystring+"I am print 1");
} public void Print2(string mystring) { Console.WriteLine(mystring+ "I am print 2"); }
static void Main(string[] args)
{
Program program = new Program(); MyDel my;
my = program.Print2;//方法后面不加()
my += program.Print1; my("KKK");//最后运行委托时,后面再加括号
Console.ReadKey(); }
}
}