What is the difference between checked and unchecked?

后端 未结 5 1014
情话喂你
情话喂你 2021-01-17 10:01

What is the difference between

checked(a + b)

and

unchecked(a + b)

?

5条回答
  •  孤街浪徒
    2021-01-17 10:06

    The other answers cover the difference between the two. One thing worth noting is that if a and b are floats there will be no difference. It only works for integer operations.

    There is also a build option you can set so everything is checked. This will mean your app runs slightly slower but you won't need to put checked around your arithmetic operations.

    Here is a nice writeup that describes some pitfalls: http://www.codeproject.com/KB/cs/overflow_checking.aspx

提交回复
热议问题