Handling integer overflow is a common task, but what\'s the best way to handle it in C#? Is there some syntactic sugar to make it simpler than with other languages? Or is th
The best way is as Micheal Said - use Checked keyword. This can be done as :
int x = int.MaxValue; try { checked { int test = x * 2; Console.WriteLine("No Overflow!"); } } catch (OverflowException ex) { Console.WriteLine("Overflow Exception caught as: " + ex.ToString()); }