Demonstates using checked keyword to detect an overflow
// Compile this program with the following command line:
// C:>csc /checked OvrFlow2.cs
using System;
public class OvrFlow2
{
static public void Main ()
{
int large = 2147483647;
int larger = large;
unchecked
{
++larger;
larger *= 2;
}
Console.WriteLine ("large = " + large);
Console.WriteLine ("larger = " + larger);
}
}
Related examples in the same category