OverflowCheck : checked unchecked « Data Types « C# / C Sharp






OverflowCheck

 

using System;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        byte destinationVar;
        short sourceVar = 281;
        destinationVar = checked((byte)sourceVar);
        Console.WriteLine("sourceVar val: {0}", sourceVar);
        Console.WriteLine("destinationVar val: {0}", destinationVar);
    }
}

 








Related examples in the same category

1.Checked and Unchecked
2.Checking for overflows.
3.unchecked int overflow
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