建设网站机构服饰网站模板
1.最常用的预处理器指令#region #endregion,来定义可在大纲中折叠的代码区域.
#region MyClass def
 public class MyClass
 {
     static void Main()
     {
     }
 }
 #endregion
2.定义符号预处理器指令:来定义或取消定义条件编译的符号:
#define:定义符号。
#undef:取消定义符号。
3.条件预处理器指令:#if,#elif, #else,endif.
可以在代码文件的顶部通过#define/#undef 指令定义符号,用于指定程序代码编译的条件,可以使用 #if 、#elif 、#endif来测试符号.
当您将#define定义的符号用作传递给 #if 指令的表达式时,此表达式的计算结果为 true,将#undef定义的符号用作传递给 #if 指令的表达式时,此表达式的计算结果为 false.
符号可用于指定编译的条件。 可通过 #if 或 #elif 测试符号。 还可以使用 ConditionalAttribute 来执行条件编译,如下例所示:
 #define CalledTestM1
 #undef CalledTestM2
#define DEBUG
 #undef TRACE
using System;
public class TestDefine
 {
     static void Main()
     {
         //调用TestConditionalM1
         TestConditionalM1();
         //不调用TestConditionalM2
         TestConditionalM2();
#if (DEBUG)
         Console.WriteLine("Debugging is enabled.");
 #endif
#if TRACE
      Console.WriteLine("Tracing is enabled.");
 #endif
     }
    [Conditional("CalledTestM1")]
     static void TestConditionalM1() { Console.WriteLine("Conditional M1 is Called"); }
     [Conditional("CalledTestM2")]
     static void TestConditionalM2() { Console.WriteLine("Conditional M2 is Called"); }
 }
 // Output:
 // Conditional M1 is Called
 // Debugging is enabled.
