using System;
using System.Collections.Generic;
using System.Linq;
namespace NilPointer
{
class Program
{
static void Main(string[] args)
{
var numbers = new List<int> {
50, 2, -7, 11,-9, 26, 6, 42
};
var sum1 = numbers.Sum(number => number);
Console.WriteLine("Sum 1: " + sum1);
var sum2 = numbers.Where(number => number > 0).Sum(number => number);
Console.WriteLine("Sum 2: " + sum2);
Console.ReadLine();
}
}
}
Output
Sum 1: 121
Sum 2: 137