The use of the #define, #if, and #endif preprocessor directives : Macro « Development Class « C# / C Sharp






The use of the #define, #if, and #endif preprocessor directives

The use of the #define, #if, and #endif preprocessor directives

#define DEBUG
   
class Test 
{
  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");
#endif
      goto myLabel;
    }
   
    System.Console.WriteLine("total = " + total);
   
  }
   
}
           
       








Related examples in the same category

1.#undef, #elif, and #else preprocessor directives#undef, #elif, and #else preprocessor directives
2.Define macro for conditional compile
3.Macro in action