C# Unchecked Statement

In this article i am explaining about Unchecked key word. The unchecked statement ignores the stack overflow exception and executes the program so, the output can be incorrect.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Unchecked_Statement
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            // assign maximum value
            n = int.MaxValue;
            try
            {
                unchecked
                {
                    // forces stack overflow exception
                    n = n + 1;
                    Console.WriteLine(n);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.ReadLine();
        }
    }
}

2 thoughts on “C# Unchecked Statement

Author gravatar
Pawan Shukla April 20, 2017, 7:45 pm

Very helpful

Author gravatar
valerieOa April 20, 2017, 9:47 pm

Thanks for the helpful content. It is also my opinion that mesothelioma cancer has an incredibly long latency time period, which means that the signs of the disease would possibly not emerge till 30 to 50 years after the original exposure to asbestos. Pleural mesothelioma, which is the most common form and has effects on the area about the lungs, might cause shortness of breath, breasts pains, and a persistent cough, which may produce coughing up body.
[url=http://evan9d.tumblr.com/]valerieOa[/url]

Leave a Reply

Your email address will not be published. Required fields are marked *