Iterating until int.MaxValue reached

后端 未结 4 1825
無奈伤痛
無奈伤痛 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:55

    It's called an overflow - the integer wraps around to the lowest possible negative value.

    If you want it to stop at maxInt you should replace the <= with a < - at present you can never stop the loop as counter can never be bigger can maxIni.

提交回复
热议问题