You can't return multiple values from a delegate. As you've shown, you can only get the return value of the last called function. If you really want to get all the values, I'd suggest something like the following:
Code:
public delegate void Calc(string t, Collection<int> retVals);
static void Main(string[] args)
{
Program t = new Program();
string st = "test";
Calc c = new Calc(t.DoubleL);
Collection<int> retVals = new Collection<int>();
c += new Calc(t.HalfL);
c += new Calc(t.Length);
c(st, retVals);
foreach(int i in retVals)
Console.WriteLine(i);
Console.ReadLine();
}
private void DoubleL(string t, Collection<int> retVals)
{
Console.WriteLine("DoubleL");
retVals.Add(t.Length * 2);
}
private void HalfL(string t, Collection<int> retVals)
{
Console.WriteLine("HalfL");
retVals.Add(t.Length / 2);
}
private void Length(string t, Collection<int> retVals)
{
Console.WriteLine("Length");
retVals.Add(t.Length);
}
In general, relying on the return value of a delegate is a bad practice. If the delegate instance is not private, then there is the possibility that other users could hook up to the delegate, becoming the last in line and hence returning their value. If the delegate instance is private, then it becomes a code maintainence issue. It's very easy for someone else to come back around to your piece of code and subscribe a few more functions to your delegate without understanding that you need a specific return value.