Show/Hide Toolbars

XSharp

The -define compiler option defines name as a symbol in all source code files your program.

Syntax

-define:name[;name2]  

Arguments

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

Remarks

The -define option has the same effect as using a #define preprocessor directive except that the compiler option is in effect for all files in the project. A symbol remains defined in a source file until an #undef directive in the source file removes the definition. When you use The -define option, an #undef directive in one file has no effect on other source code files in the project.

 

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 X# compiler defines a couple of symbols automatically. See the Macros topic elsewhere in this documentation.

 
To set this compiler option in the Visual Studio development environment

1.Open the project's Properties page.

2.On the Build tab, type the symbol that is to be defined in the Conditional compilation symbols box. For example, if you are using the code example that follows, just type xx into the text box.

 

For information on how to set this compiler option programmatically, see DefineConstants.

Example

 

 

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