2 ms·
So you can't use IEnumerable<T>.Sum if T is a custom type implementing operator+ ?
by masfuerte 2y ago
So you can't use IEnumerable<T>.Sum if T is a custom type implementing operator+ ?
- deleted 2y ago[deleted]
- neonsunset 2y agoYou could, but .Sum is a little more specific than that - it is non-overflowing sum. Historically, constraining generic arguments on addition was problematic - the full feature set of numeric types was "lifted" to be fully representable through generics only recently[0]. With that said, there is an open proposal[1] to introduce additional generic math overloads to IEnumerable<T> methods, but it hasn't seen much activity as the existing overloads cover most commonly used numeric types already. [0]: https://learn.microsoft.com/en-us/dotnet/standard/generics/math https://learn.microsoft.com/en-us/dotnet/standard/generics/m... [1]: https://github.com/dotnet/runtime/issues/64031 https://github.com/dotnet/runtime/issues/64031