Fun Sum

Watch out when summing up numbers as bugs can sneak up on you without a warning. Check these two approaches out:

int maxInt = int.MaxValue;
Console.WriteLine(maxInt + 1); // Prints out -2147483648
Console.WriteLine(new List<int> { maxInt, 1 }.Sum()); // Throws System.OverflowException

Disclaimer:
A guest on .NET Rocks, “Testing Software using PEX“, show asked which approach throws an exception. Now, we know…