关于c#:为什么这会返回0?


Why does this return 0?

本问题已经有最佳答案,请猛点这里访问。
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
namespace test_warmup
{
    class Program
    {
        static void Main(string[] args)
        {
            int test = -1110835200;
            test = test * 1700397056;
            Console.WriteLine(test);
        }
    }
}

-1110835200 * 1700397056 = -1888860903781171200

以十六进制显示,即-0x1a3694fc_00000000

在C#中,int仅32位,因此结果被截断为0

换句话说,该乘法的结果太大而无法放入您要为其分配的变量中,而适合的部分全为零。