Information Technology Reference
In-Depth Information
The #define and #undef Directives
A compilation symbol is an identifier that has only two possible states. It is either defined or
undefined . A compilation symbol has the following characteristics:
Can be any identifier except true or false . This includes C# keywords, and identifiers
declared in your C# code—all of which are fine.
￿
￿
Has no value. Unlike C and C++, it does not represent a string.
As shown in Table 22-1:
￿The #define directive declares a compilation symbol.
￿The #undef directive undefines a compilation symbol.
#define PremiumVersion
#define EconomyVersion
...
#undef PremiumVersion
The #define and #undef directives can be used only at the top of a source file, before any
C# code is listed. After the C# code has started, the #define and #undef directives can no longer
be used.
using System; // First line of C# code
#define PremiumVersion // Error
namespace Eagle
{
#define PremiumVersion // Error
...
The scope of a compilation symbol is limited to a single source file. Redefining a symbol
that is already defined is perfectly fine—as long as it's before any C# code, of course.
#define AValue
#define BValue
#define AValue // Redefinition is fine.
Search WWH ::




Custom Search