#define flag and check it existance - CSharp Language Basics

CSharp examples for Language Basics:Preprocessor

Description

#define flag and check it existance

Demo Code

#define TESTING/*from   w w  w  .java2s.  c o  m*/
using System;
class Car
{
   int odometer = 0;
   int moveCounter = 0;
   public double MoveForward(int distance)
   {
      moveCounter++;
      odometer += distance;
      Console.WriteLine("Car is moving forward by {0} kilometers", distance);
      #if TESTING
      Console.WriteLine("Testing. Odometer: {0}", odometer);
      #endif
      return (odometer / moveCounter);
   }
}
class Controller
{
   public static void Main()
   {
      double averageMoveDistance;
      Car myCar = new Car();
      averageMoveDistance = myCar.MoveForward(20);
      averageMoveDistance = myCar.MoveForward(10);
      #if TESTING
      Console.WriteLine("Testing. averageMoveDistance: {0}", averageMoveDistance);
      #endif
   }
}

Result


Related Tutorials