I have an issue that I wish to add function calls to a delegate, but each of these function calls will have a unique parameter. I cannot figure it out or find a solution elsewhere so I am turning to you guys :)
Some pseudo below..
(So basically, I am creating a delegate and an event and the AddToDelegate function is supposed to add the function calls to the event (with a unique value), then the GetData function returns all the responses in one string - the problem comes in the AddToDelegate function as the line a += new A(SomeFunc)(i.ToString());
should really only be a += new A(SomeFunc);
)
Is there a way to do this with delegates - or am I barking up the wrong tree?
public delegate string A(string s);
public event A a;
public void AddToDelegate()
{
for (int i = 0; i < DelegateList.Length; i++)
{
a += new A(SomeFunc)(i.ToString());
}
}
public string GetData()
{
StringBuilder _sb = new StringBuilder();
if (a != null)
{
Delegate[] DelegateList = a.GetInvocationList();
for (int i = 0; i < DelegateList.Length; i++)
{
_sb.Append(((A)DelegateList[i]));
}
}
return _sb.ToString();
}