Catching an underflow : byte overflow « Data Type « C# / CSharp Tutorial






using System;

class MainClass
{
  static void Main(string[] args)
  {
    Console.WriteLine("System.Byte stats:");
    Console.WriteLine("Max value of byte is {0}.", byte.MaxValue);
    Console.WriteLine("Min value of byte is {0}.", byte.MinValue);

    Console.WriteLine("Catching an underflow");
    try
    {
      byte a = 9, b = 9;
      byte c = (byte)(a + b + -100);
    }
    catch(OverflowException e){Console.WriteLine(e);}

  }
}
System.Byte stats:
Max value of byte is 255.
Min value of byte is 0.
Catching an underflow








2.16.byte overflow
2.16.1.byte overflow with unchecked
2.16.2.Catching an underflow