/define (Preprocessor Definition) (C# Compiler Options)
The /define option defines name as a symbol in your program.
/define:name[;name2]
The /define option 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
The C# compiler itself defines no symbols or macros that you can use in your source code; all symbol definitions must be user-defined.
Note |
|---|
| The C# #define does not allow a symbol to be given a value, as in languages such as C++. For example, #define cannot be used to create a macro or to define a constant. If you need to define a constant, use an enum variable. If you want to create a C++ style macro, consider alternatives such as generics. Since macros are notoriously error-prone, C# disallows their use but provides safer alternatives. |
To set this compiler option in the Visual Studio development environment
-
Open the project's Properties page. For more information, see How to: Set Project Properties (C#, J#).
-
Click the Build property page.
-
Modify the Conditional Compilation Symbols property.
For information on how to set this compiler option programmatically, see DefineConstants.
Note