Is there a constraint that restricts my generic method to numeric types?

Can anyone tell me if there is a way with generics to limit a generic type argument T to only:

  • Int16
  • Int32
  • Int64
  • UInt16
  • UInt32
  • UInt64

I’m aware of the where keyword, but can’t find an interface for only these types,

Something like:

static bool IntegerFunction<T>(T value) where T : INumeric 

24 Answers
24

Leave a Comment