Can anyone tell me if there is a way with generics to limit a generic type argument T
to only:
Int16
Int32
Topic is old but for future readers:
This feature is tightly related to Discriminated Unions
which is not implemented in C# so far. I found its issue here:
https://github.com/dotnet/csharplang/issues/113
This issue is still open and feature has been planned for C# 10
So still we have to wait a bit more, but after releasing you can do it this way:
static bool IntegerFunction(T value) where T : Int16 | Int32 | Int64 | ...