uncheck int overflow - CSharp Language Basics

CSharp examples for Language Basics:int

Description

uncheck int overflow

Demo Code

using System;/*w  w  w . j  av a 2s  .  com*/
class Traveling
{
   public static void Main()
   {
      int totalTime;
      int totalEnergy;
      int totalRadiation;
      int distance = 2100000;
      int timeFactor = 100000;
      int energyFactor = 20;
      int radiationFactor = 40000;
      totalTime = unchecked(distance * timeFactor);
      totalEnergy = checked(distance * energyFactor);
      totalRadiation = distance * radiationFactor;
      Console.WriteLine("Total time: " + totalTime);
      Console.WriteLine("Total energy: " + totalEnergy);
      Console.WriteLine("Total radiation: " + totalRadiation);
   }
}

Result


Related Tutorials