I want to instantiate a generic collection (a Dictionary in this case) but in the generic type declaration I want constraint the parameter type to more then 1 class.
Here is the example code:
I have many classes with this declaration:
public class MyClass1 : UserControl, IEspecialOptions
public class MyClass2 : UserControl, IEspecialOptions, IOtherInterface
etc.
This is what I want:
Dictionary<int, T> where T:UserControl, IEspecialOptions myDicc = new Dictionary<int, T>();
This looks very nice but don’t compile.
Do you know how to contraint the second parameter to inherate from 2 classes/interfaces?
I’m limited to .net 2.0
Thanks in advance
You cannot. But you can create an abstract class that both inherits
UserControland implementsIEscpecialOptionsand then constraint the generic parameter to be of the abstract type.