How to store delegates in a List

Viewed 34076

How can I store delegates (named, anonymous, lambda) in a generic list? Basically I am trying to build a delegate dictionary from where I can access a stored delegate using a key and execute it and return the value on demand. Is it possible to do in C# 4? Any idea to accomplish it? Note : Heterogeneous list is preferable where I can store any kind of delegates.

5 Answers
List<System.Delegate> something;
something.Add(new Action(()=> DoSomething()));

If you want to customize the key, you can use Dictionary like above

Related