Change value type when doing Sum in CSharp
Description
The following code shows how to change value type when doing Sum.
Example
using System;/*from w w w . j av a 2s . c o m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
Random generator = new Random(0);
int[] numbers = new int[1000];
for (int i = 0; i < 1000; i++)
{
numbers[i] = generator.Next();
}
var queryResults = from n in numbers where n > 100 select n;
Console.WriteLine("Sum of Numbers > 100");
Console.WriteLine(queryResults.Sum(n => (long)n));
}
}
The code above generates the following result.