I am trying to create a generic class whose implementation depends on the type being an Int32, Int64, double, float, or decimal.
class Calculator<T> where T: int, double, float, decimal
This is not right but I’m having troubles with the syntax
You can’t specify a constraint on a type parameter such that it has to be one of a specified set of types, no. See MSDN for a list of valid constraints.
For those particular types you could specify:
That’s likely to restrict the set fairly well, although it would also allow other primitive types such as
byteandulong.