The first thing to know is that the int type is a 32-bit number in C #. This allows you to know the range of values for int is ( -2147483648~2147483647) when you want to use the minimum or maximum value of int, you can use Int. Both the MinValue and Int.maxvalue properties.
Here we are going to talk about an int number overflow, in fact, when the maximum of +1 in the int type becomes the minimum value. When we want this int value to not exceed the limit, you can manually enable the overflow check feature.
In Visual Studio, you are allowed to set project properties to enable or disable overflow checking. Solution Explorer------Right-click to select Properties-------in the Properties dialog box, tick generate---------Click the Advanced button in the lower right corner--------the check operation overflow/underflow option in the Advanced Build Settings dialog box
You can use the checked and unchecked keywords in your code to selectively open and close integer overflow checking for a specific part of a program that overrides the project's compiler options.
The checked keyword is open arithmetic overflow check, unchecked opposite.
The above program sets the A variable to the maximum value of the int data, and throws a OverflowException exception when the checked detection is performed.
The use of unchecked forces a block of code that does not check for overflow. This exception is not thrown OverflowException.
It is important to note that only integer operations in checked fast are checked, and for fast method calls, the integer operation in the called method is not checked.
Exception handlers and the Visual Studio debugger
In Visual Studio, the debugger will break the application by default only when an unhandled exception occurs, but sometimes you need to debug the application itself, which requires that the agenda be tracked before the application catches it. It is easy to enable this feature:
Select-----Debug Window-----Exception settings
C # uses checked and unchecked