Enumerable.Sum<T>() is defined only for IEnumerable<T> , where T in
double, double? int, int? decimal, decimal? long, long? float, float?
This is because there is no addition operator * for short or any other primitive type ( short + short is int , for example).
You must say:
short[] numbersArray = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int sumArray = numbersArray.Sum(x => (int)x);
and less explicitly you can get away with
short[] numbersArray = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int sumArray = numbersArray.Sum(x => x);
In this case, you are now causing overload:
int Enumerable.Sum<short>( this IEnumerable<short> source, Func<short, int> selector )
* : Here I mean the "operator" in the sense of the function F:(short x short) -> short .
jason
source share