A generic class which can take only certain types
A generic class which can take only certain types Suppose, I want to create a generic class that can take only int and double as types. int double public class A<T> where T: int, double { public T property{get;set;} } For instance: A<int> i = new A<int>(); i.property = 10; A<double> d = new A<double>(); d.property = 0.01; but, this is not working. How can I do that? Is there any other way I can address my specific requirement? You can't - how would you do anything with property within A ? – Lee Jun 27 at 18:32 property A 6 Answers 6 There's no such constraint exists in C#. But for value type you can use struct as generic constraint. It will only allow non-nullable value types. struct public class A<T> w...