I am not sure for what you'll need this but this should work for you:
private void test()
IList<object> list = new List<object>();
Func<string, string> anyFunction = AnyFunction;
Action voidFunction = AnyVoidFunction;
foreach (var item in list)
if (item is string)
if (item is Func<string,string>)
var result = (item as Func<string, string>)("Call it");
Debug.WriteLine("Function result is: "+result);
if(item is Action)
(item as Action)();
//as it is a list you can of course index it
var indexedItem = list;
private string AnyFunction(string inputString)
return "Anything "+ inputString;
private void AnyVoidFunction()
The variable 'list' will hold the string "mystring", the function "AnyFunction" and the method "AnyVoidFunction".
Then the list is iterated. The output will be:
Function result is: Anything Call it
This will work with all the arrays, lists, dictionaries, stacks, queues and so on in C#.
btw.: As the focus of the question is not really game releated but more of a programming question: https://stackoverflow.com/ will be better to ask.