#undef, #elif, and #else preprocessor directives : Preprocessor Directives « Language Basics « C# / C Sharp






#undef, #elif, and #else preprocessor directives

#undef, #elif, and #else preprocessor directives
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example4_17.cs illustrates the use of the
  #undef, #elif, and #else preprocessor directives
*/

#define DEBUG
#undef DEBUG
#define PRODUCTION

public class Example4_17
{

  public static void Main()
  {

    int total = 0;
    int counter = 0;

    myLabel:
    counter++;
    total += counter;
    System.Console.WriteLine("counter = " + counter);
    if (counter < 5)
    {
#if DEBUG
      System.Console.WriteLine("goto myLabel");
#elif PRODUCTION
      System.Console.WriteLine("counter < 5");
#else
      System.Console.WriteLine("goto myLabel, counter < 5");
#endif
      goto myLabel;
    }

    System.Console.WriteLine("total = " + total);

  }

}

           
       








Related examples in the same category

1.line number
2.precompile marco: define, undef, elif, endif
3.#undef Marco
4.Use marco to define flag variable
5.Demonstrates the use of a conditional methodDemonstrates the use of a conditional method
6.#define, #if, and #endif preprocessor directives#define, #if, and #endif preprocessor directives
7.Demonstrate #if, #endif, and #defineDemonstrate #if, #endif, and #define
8.Use a symbol expressionUse a symbol expression
9.Demonstrate #elseDemonstrate #else
10.Demonstrate #elifDemonstrate #elif
11.Preprocessor 2Preprocessor 2