我有很简单的委托Invoke方法的所有结果:如何获得
public delegate int Compute(int i, int j);
和一些功能:
static int sum(int x, int y)
{
return x + y;
}
static int diff(int x, int y)
{
return x - y;
}
static int times(int x, int y)
{
return x * y;
}
然后我声明的事件为:
public static event Compute e;
在主要我正在为事件添加功能:
e += new Compute(sum);
e += new Compute(diff);
e += new Compute(times);
最后,我想编写的函数的所有结果,所以:
Console.WriteLine(e.Invoke(3,4));
我的理解Invoke
方法调用在事件中的所有功能。但在我的情况下,我只看到最后一个附加功能的结果 - 所以12
。我如何获得Invoke
方法的所有结果?
如果函数没有返回任何类型(它们是void类型)没有问题,但是如果函数返回一些东西 - 那就是。
这似乎有点[xy问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)你真的想用这个解决什么问题? – asawyer