开发者

Generics that restricts the types to Int, Double, long [duplicate]

This question already has answers here: Is there a constraint that restricts my generic method to numeric types? (24 answers) Closed 9 years ago. 开发者_如何学运维

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜