[Question] Numeric integer and decimal constraints #2038
-
There are open issues requesting a way to restrict generic types that are numbers, but is it also considered to indicate whether that numeric parameter is integer? For example to achieve something like the following pseudo-code: public static TNumeric GetWrappedValue<TNumeric, TInteger>(this TNumeric arg0, TInteger arg1)
where TNumeric: struct, "numeric"
where TInteger: struct, "integer"
{
return arg0 % arg1;
} ... beaing arg1 of type byte, int, long ... |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
See #110 and #1711 . I don't think we'd have language-built-in constraints for these particular things, but you could use those features to achieve that if you wanted to. |
Beta Was this translation helpful? Give feedback.
-
I see. Thanks. |
Beta Was this translation helpful? Give feedback.
-
@Ultrahead does that solve the issue? Would you like to close it? |
Beta Was this translation helpful? Give feedback.
-
@amis92 that depends on the final implementation of such features when available. |
Beta Was this translation helpful? Give feedback.
-
Now that C# 9 is coming next, will it include a feature that allows to achieve something as shown in my initial post? Or ... public static TNumeric Add(this TNumeric arg0, TNumeric arg1) |
Beta Was this translation helpful? Give feedback.
-
No, neither shapes nor numeric constraints will be part of C# 9 |
Beta Was this translation helpful? Give feedback.
-
Well, let's hope they make it for C# 10, then. |
Beta Was this translation helpful? Give feedback.
See #110 and #1711 . I don't think we'd have language-built-in constraints for these particular things, but you could use those features to achieve that if you wanted to.