In this chapter you will learn:
- What is unchecked statement in C#?
- What is the advantage and disadvantage of Unchecked Statement?
- How to use unchecked statement in C sharp programming?
The unchecked statement ignores the stack overflow exception and executes the program so, the output can be incorrect.
static void Main(string args)
// assign maximum value
num = int.MaxValue;
// forces stack overflow exception
num = num + 1;
catch (Exception e)
Here, the correct output should be 2147483648 but the output is -2147483648 which is wrong because of unchecked statements as it ignores exception and put output on screen.
In this chapter you learned what unchecked statement is in C# and how to use it in programming. In next chapter you will learn about Lock Statement in C#.