I've got an integer array that contains two values, each the maximum value of int32:
int[] factors = new int[] { 2147483647, 2147483647 };
I'm trying to get the product of these two numbers to create an OverflowException:
try
{
int product = factors[0] * factors [1];
}
catch(Exception ex)
{
}
Much to my surprise (and dismay), product actually returns a value of 1. Why is this, and how would I go about throwing an exception when the product of two integers exceeds int.MaxValue?