Export (0) Print
Expand All

/define (Preprocessor Definition)



name, name2
The name of one or more symbols that you want to define.


The /define option defines name as a symbol in your program. It has the same effect as using a #define preprocessor directive in your source file. A symbol remains defined until an #undef directive in the source file removes the definition or the compiler reaches the end of the file.

You can use symbols created by this option with #if, #else, #elif, and #endif to compile source files conditionally.

/d is the short form of /define.

You can define multiple symbols with /define by using a semicolon or comma to separate symbol names. For example:


To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C# Project Properties.
  2. Click the Configuration Properties folder.
  3. Click the Build property page.
  4. Modify the Conditional Compilation Constants property.

To set this compiler option programmatically

See DefineConstants Property.


// preprocessor_define.cs
// compile with: /define:xx
// or uncomment the next line
// #define xx
using System;
public class Test 
   public static void Main() 
      #if (xx) 
         Console.WriteLine("xx exists");
         Console.WriteLine("xx does not exist");

See Also

C# Compiler Options

© 2014 Microsoft