Generally speaking, if your object reacts differently based on the generic type argument, you probably shouldn't be using generics in this case. Generics are great for situations where you want to do always the same thing, no matter what the actual type used.
Therefore, generic constraints will only allow you to list one base class for a type argument. Any actual types passed to the respective type arguments are meant to be a part of the given inheritance hierarchy starting with the base class you specified, so users of your class can specify any type that matches the base class or any of its subclasses.
At the same time, you, the author of the generic class, can safely assume that the specified type has (at least) the interface of the base class indicated by the constraint. Hence, you may access any members of the base class.
If you want to allow either string
or int
, imagine what members that could be. Both are derived directly from System.Object
, hence the restriction would make no sense as it is no restriction; every type is derived from System.Object
.
Summarizing, if you really want to treat string
and int
differently, this is definitely a case for offering two overloads rather than one generic class.