Generic Type Parameter constraints in C# .NET
- by activwerx
Consider the following Generic class:
public class Custom<T> where T : string
{
}
This produces the following error:
'string' is not a valid constraint. A type used as a constraint must
be an interface, a non-sealed class or a type parameter.
Is there another way to constrain which types my generic class can use?
Also, can I constrain to multiple types?
E.G.
T can only be string, int or byte