Reputation: 2651
Is it possible to define a generic class where T can belong only to value type (such as int, double and so on)?
Upvotes: 0
Views: 112
Reputation: 101681
yes, you need a struct
constraint:
class OnlyStructs<T> where T : struct { }
But you should be aware of that this also allows user-defined structs, not just int
,double
etc.. Unfortunately there is no built-in way to restrict T
for only specific types like where T : int,double,float
.
Upvotes: 5