Iterating until int.MaxValue reached

后端 未结 4 1829
無奈伤痛
無奈伤痛 2021-01-14 19:01

As a little test I wanted to see how long it would take to count to int.MaxValue in a C# console application. Every few hours I checked the progress. Last night when I thoug

4条回答
  •  春和景丽
    2021-01-14 19:58

    When you add 1 to an Int32.MaxValue you will end up with Int32.MinValue.

    int a = Int32.MaxValue;
    a++; // a is now -2147483648
    

提交回复
热议问题