Storing a generic class in a dictionary

Is it possible to store a generic class object in a Dictionary? If so, how?

I've got an abstract generic class, Comparison<T>, and several concrete inherited generic classes. The actual types will be determined by a configuration file at runtime. I need to store a collection of any number of any combination of these inherited classes. Since they will all be Comparison types I was hoping to use a Dictionary to store them, but since the actual type T may well differ between them, can I do this, or do I need to revert to a Hashtable?

Dictionary<string, Comparison<T>> comparisons =newDictionary<string, Comparison<T>>();

[956 byte] By [griff_1000] at [2007-12-23]
# 1
You cannot do that, but what you can do is:

Dictionary<string, Comparison<BaseClassOrInterface>> comparison = new Dictionary<string, Comparison<BaseClassOrInterface>>();

Assuming your concrete types have BaseClassOrInterface as a base.

RabbiJosephGordon at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

I think I've gotten around it by re-arranging my class structure -

Now have Comparison as non-generic abstract class with minimal non-generic functionality

GenericComparison<T> inherits from Comparison, remains abstract and adds base generic functionality

Concrete Comparison classes inherit from GenericComparison<T>

The Dictionary definition is now:
Dictionary<string, Comparison> comparisons = new Dictionary<string, Comparison>();

griff_1000 at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified