Preprocessing Directives: define : define « Preprocessing Directives « C# / CSharp Tutorial






  1. The #define directive defines a character sequence called a symbol.
  2. The existence or nonexistence of a symbol can be determined by #if or #elif

The general form for #define:

#define symbol
#define DEBUGLOG

using System;

class MainClass
{
    public static void Main()
    {
        #if DEBUGLOG
        Console.WriteLine("In Main - Debug Enabled");
        #else
        Console.WriteLine("In Main - No Debug");
        #endif
    }
}
In Main - Debug Enabled








16.1.define
16.1.1.A list of preprocessor commands available in C#:
16.1.2.Preprocessing Directives: define
16.1.3.Use a symbol expression.
16.1.4.Use the Conditional attribute with define