In C#: How to declare a generic Dictionary with a type as key and an enumeration of that type as val

Posted by Marcel on Stack Overflow See other posts from Stack Overflow or by Marcel
Published on 2010-05-31T14:56:02Z Indexed on 2010/06/01 7:53 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

Hi all,

I want to declare a dictionary that stores typed IEnumerable's of a specific type, with that exact type as key, like so: (Edited to follow johny g's comment)

private IDictionary<Type, IEnumerable<T>> _dataOfType where T: BaseClass; //does not compile!

The concrete classes I want to store, all derive from BaseClass, therefore the idea to use it as constraint. The compiler complains that it expects a semicolon after the member name.

If it would work, I would expect this would make the later retrieval from the dictionary simple like:

IEnumerable<ConcreteData> concreteData;
_sitesOfType.TryGetValue(typeof(ConcreteType), out concreteData);

How to define such a dictionary?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary