我有一個包含兩個值,每個INT32的最大值一個整數數組:我試圖到C#倍率值int.MaxValue的兩個變量不會導致發生OverflowException
int[] factors = new int[] { 2147483647, 2147483647 };
獲得這兩個數的乘積來創建一個OverflowException異常:
try
{
int product = factors[0] * factors [1];
}
catch(Exception ex)
{
}
出乎我的意料(和沮喪),產品實際上返回值1。這是爲什麼,我怎麼會去拋出一個異常時,兩個整數的乘積超過int.MaxValue?
你能不能讓 '產品' 的Int64? –