unchecked int overflow : checked unchecked « Data Types « C# / C Sharp






unchecked int overflow

 
using System;
   
class IntegerOverFlowConst
{
    static void Main()
    {
        const ushort MAXUSHORT = 65535;
        const ushort ONE = 1;
   
        unchecked
        {
            ushort total = (short)MAXUSHORT + ONE;
        }
    }
}

 








Related examples in the same category

1.OverflowCheck
2.Checked and Unchecked
3.Checking for overflows.
4.Operators and Expressions:Checked and Unchecked Expressions
5.Demonstates using checked keyword to detect an overflowDemonstates using checked keyword to detect an overflow
6.Demonstates using checked keyword to detect an overflow 2Demonstates using checked keyword to detect an overflow 2