Original Post
What if you add several functions to a delegate, and the functions have return values? When you invoke the delegate, each function in its invocation list is called, but how can you capture the return values? Also, if you are adding multiple functions to a delegate, is this the way you do it (first set the delegate to null, then use +=):
// Define the delegate type.
public delegate float BinaryOp(float x, float y);
class Program
{
static void Main(string[] args)
{
Program p = new Program();
BinaryOp f = new BinaryOp(p.Add);
BinaryOp g = new BinaryOp(p.Sub);
BinaryOp h = new BinaryOp(p.Mul);
BinaryOp funcList = null;
funcList += f;
funcList += g;
funcList += h;
funcList(2,3);
}
float Add(float x, float y)
{
return x + y;
}
float Sub(float x, float y)
{
return x - y;
}
float Mul(float x, float y)
{
return x*y;
}
}