| only for RuBoard - do not distribute or recompile |
Preprocessor directives supply the compiler with additional information about regions of code. The most common preprocessor directives are the conditional directives, which provide a way to include or exclude regions of code from compilation. For example:
#define DEBUG
using System;
class MyClass {
int x;
public void Foo( ) {
# if DEBUG
# warning "Debug mode is ON"
Console.WriteLine("Testing: x = {0}", x);
# endif
}
}
In this class, the statement in Foo is compiled conditionally, dependent upon the presence of the user-selected DEBUG symbol. If you remove the DEBUG symbol, the statement isn't compiled. Preprocessor symbols can be defined within a source file as just shown and can be passed to the compiler with the /define:symbol command-line option.
The #error and #warning symbols prevent accidental misuse of conditional directives by making the compiler generate a warning or error given an undesirable set of compilation symbols.
The C# language supports the preprocessor directives shown in Table 2-4.
| only for RuBoard - do not distribute or recompile |