Generic type parameter in .net(C#) whose value can by one of specified types?-Collection of common programming errors
Lets say I have classes ClassA
, ClassB
, ClassC
. All of them inherit from object
and non of them implements any interface.
Is it possible in C# to declare generic interface that will take generic argument T
and that T
may be either ClassA
or ClassB
or ClassC
?
So I would have something like
public interface MyInterface where T: ClassA | ClassB | ClassC {
...
}
If it is possible what’s the syntax?
Note: I know I could have those classes ClassA
, ClassB
, ClassC
to implement some interface and than use it as constrain of T
but before I create an interface that have no methods I want to know that there is no better way.