Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

/define (Preprocessor Definition)

/define:name[;name2]

where:

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

Remarks

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:

/define:DEBUG;TUESDAY

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.

Example

// 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");
      #else
         Console.WriteLine("xx does not exist");
      #endif
   }
}

See Also

C# Compiler Options

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.