delegate void MyDelegate(string s);
public class MyClass
{
public void SayHello(string who)
{
System.Console.WriteLine( who "hello!");
}
public void SayGoodBye(string who)
{
System.Console.WriteLine( who "good bye!");
}
}
public class TestMyClass
{
public static void Main(string[] args)
{
MyClass myClass1=new MyClass();
MyDelegate myDelegate,myDelegate1;
myDelegate=new MyDelegate(myClass1.SayHello);
myDelegate1=new MyDelegate(myClass1.SayGoodBye);
myDelegate =myDelegate1;
//这样调用myDeletage就相当于同时调用了
myClass1.SayHello和myClass1.SayGoodBye
myDelegate("love.net ");
//执行结果输出love.net hello! love.net good bye!
}
}
|