Can anyone tell me if there is a way with generics to limit a generic type argument T
to only:
Int16
Int32
What is the point of the exercise?
As people pointed out already, you could have a non-generic function taking the largest item, and compiler will automatically convert up smaller ints for you.
static bool IntegerFunction(Int64 value) { }
If your function is on performance-critical path (very unlikely, IMO), you could provide overloads for all needed functions.
static bool IntegerFunction(Int64 value) { }
...
static bool IntegerFunction(Int16 value) { }