Is it possible to have a type constraint that is an “or” of two types instead of an “and”. An “and” is accomplished by putting a comma between the two types. But what about an “or”?
class Type1<T, U>
{
public static Type1<T, U> New<V>( V v )
where V : T, U
{
return new Type1<T, U>();
}
}
So in the above example, the argument passed into New() must be both a T and a U. But I want it to be either a T or a U.
There is no way to express the “or” constraint in the manner you described. However you can emulate this by having two overloads one which accepts
Uand the otherT. These two can then feed into a common function which handlesTorUNot quite sure what you’d want to do with the
TorUparameter though. Perhaps you could elaborate a bit