✅ Using System.Collections.Generic Wide-ranging Type? (T), but limiting to fewer options
For example, I'd like to create an Add method, that works for int, double, decimal and float.
I'd write
But how do I limit T to only the aforementioned four numeric types?
Relevant information is appreciated!
12 Replies
If you're using .NET 7
I'm using .NET 8.0
Preview?
Sorry, what do you mean?
The latest stable .NET version is 7
So if you're using .NET 8 it's a beta/preview version
In any case, if you're using a version >= 7 then
INumber<T>
should be availableOh, might be. I read in the "terminal?" that "XYZ feature isn't available in .NET 8.0, only available in .NET 9.0", not the exact wording, but you get it.
Okay, can you do
dotnet --list-sdks
and post the outputOh, I've seen the "where" keyword occasionally on Microsoft examples, seems like would be an interesting thing to learn
Sure
Actually I think you're just using a lower language version. That error occurs when you try using a feature from a language version that is greater than the one you're currently using.
lmao, it is 5.0.408 😂
yeah there's issue #1 probably
As mentioned, .NET 7 is the latest version, there's no reason to use 5 anymore
Thanks! I'll try to update it
If my potato laptop doesn't crash by then