Alex Rivera | Logout

Generics that restricts the types to Int, Double, long

Asked 2010-04-15T12:48:26.997
27

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?

c#
Edit
Report

1 Answer

18

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.

answered 2010-04-15T12:49:42.493

Your Answer