Take a look at the methods of the Enumerable class - it has many parameters parameterized by each supported type:
int Sum(this IEnumerable<int> source) double Sum(this IEnumerable<double> source) decimal Sum(this IEnumerable<decimal> source) long Sum(this IEnumerable<long> source) int? Sum(this IEnumerable<int?> source)
This is the only way to make the argument of the method βsummableβ.
Unfortunately, you cannot create some general method with a general restrict type parameter , which will allow only types with the + operator to be overloaded. In .NET there are no restrictions for operators, nor can operators be part of some interface (therefore, they are static). Thus, you cannot use operators with variables of a general type.
Also, if you look at the definitions of primitive .NET types, you will not find any interface that can help you - only comparison, formatting and conversion are implemented:
public struct Int32 : IComparable, IFormattable, IConvertible, IComparable<int>, IEquatable<int>
source share