Alex Rivera | Logout

How to specify types not allowed in a .NET Generics constraint?

Asked 2011-08-17T16:36:55.317
13

Is it possible to specify a constraint on a generic class that disallows certain types? I don't know if it is possible and if it is, I am not sure what the syntax would be. Something like:

public class Blah<T> where : !string {
}

I can't seem to find any notation that would allow such a constraint.

Edit
Report

1 Answer

2

Constraints can only be positive constraints, as outlined in the documentation.

The only thing you can do is specify what types can be put into the generic type, but you cannot specify what can't be put into them.

answered 2011-08-17T16:38:47.147

Your Answer