Csharp/CSharp Tutorial/Preprocessing Directives/define — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:17, 26 мая 2010
Содержание
A list of preprocessor commands available in C#:
<source lang="csharp">#define
- undef
- if
- else
- elif
- endif
- line
- error
- warning
- region
- pragma</source>
Preprocessing Directives: define
- The #define directive defines a character sequence called a symbol.
- The existence or nonexistence of a symbol can be determined by #if or #elif
The general form for #define:
<source lang="csharp">#define symbol</source>
Use a symbol expression.
<source lang="csharp">#define AAA
- define BBB
using System;
class MainClass {
public static void Main() { #if AAA Console.WriteLine("Compiled for AAA version."); #endif #if AAA && BBB Console.Error.WriteLine("Testing AAA and BBB version."); #endif Console.WriteLine("This is in all versions."); }
}</source>
Compiled for AAA version. Testing AAA and BBB version. This is in all versions.
Use the Conditional attribute with define
<source lang="csharp">#define USE_METHOD_1 using System; using System.Diagnostics; class MainClass {
[Conditional("USE_METHOD_1")] public static void Method1() { Console.WriteLine("In Method 1"); } public static void Main() { Console.WriteLine("In Main"); Method1(); }
}</source>
In Main In Method 1