Generics that restricts the types to Int, Double, long [duplicate]
Is it possible to constraint a method so that it receives only int
, double
, long
or other numerical types that has the usual numerical operations ( such as +
,-
,*
,/
) defined?
This is not possible currently.
Also, see this question for a possible workaround
No, unfortunately there is no such restriction possible. The closest you can get is using struct, IConvertible
as generic type constraint.
You may want to read this question though.
精彩评论