Overflow the max value of a System.Byte : unchecked « Data Type « C# / CSharp Tutorial






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


  class Program
  {
    static void Main(string[] args)
    {
      byte b1 = 100;
      byte b2 = 250;

      try
      {
        byte sum = unchecked((byte)(b1 + b2));
        Console.WriteLine("sum = {0}", sum);
      }
      catch (OverflowException ex)
      {
        Console.WriteLine(ex.Message);
      }
    }

  }








2.49.unchecked
2.49.1.Mark expressions as unchecked
2.49.2.An Unchecked Block Example
2.49.3.unchecked marker
2.49.4.Overflow the max value of a System.Byte