dimanche 19 mars 2017

How to limit a Type type to a specific types subset in C#

A variable of type Type can contain any type. What I need is a variable that can only contain types that inherit a specific class and implement a specific interface. How can this be specified? I have tried declaring the variable as

Type: MyClass, IMyInterface theTypeVariable;

and as

Type<MyClass, IMyInterface> theTypeVariable;

but neither works.

what's the correct way?





Aucun commentaire:

Enregistrer un commentaire