using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2014050903MultiDelegate
{
delegate void DG(string str);
class A
{
public void H(string str)
{
Console.WriteLine("\tHello,{0}\t",str);
}
public void G(string str)
{
Console.WriteLine("\tGoodbye,{0}\t", str);
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
DG m, n, p, q;
m = new DG(a.H);
n = new DG(a.G);
p = m + n ;
q = p - m;
m("M");
n("n");
p("p");
q("q");
}
}
}
执行结果为:
Hello,M
Goodbye,n
Hello,p
Goodbye,p
Goodbye,q