border="0" src="http://forum.booye.com/byhtm/1.html" frameborder="0" width="470" height="60">
#define
NOBUG
//
C#的宏定义必须出现在所有代码之前。当前只让NOBUG宏有效。
// #define BUGED
// #define WANG
// #define XIA
using System;
using System.Diagnostics; // 为了使用包含在此名称空间中的ConditionalAttribute特性
namespace ConsoleTest
{
class ToolKit
{
[ConditionalAttribute( " WANG " )] // Attribute名称的长记法
[ConditionalAttribute( " BUGED " )]
public static void Method_1() { Console.WriteLine( " Created By WANG, Buged. " ); }
[ConditionalAttribute( " WANG " )]
[ConditionalAttribute( " NOBUG " )]
public static void Method_2() { Console.WriteLine( " Created By WANG, NoBug. " ); }
[Conditional( " XIA " )] // Attribute名称的短记法
[Conditional( " BUGED " )]
public static void Method_3() { Console.WriteLine( " Created By XIA, Buged. " ); }
[Conditional( " XIA " )]
[Conditional( " NOBUG " )]
public static void Method_4() { Console.WriteLine( " Created By XIA, NoBug. " ); }
}
class MClass
{
[STAThread]
static void Main( string [] args)
{
// 虽然方法都被调用了,但只有符合条件(有效宏)的才会被执行。
ToolKit.Method_1();
ToolKit.Method_2();
ToolKit.Method_3();
ToolKit.Method_4();
Console.ReadLine();
}
}
}
// #define BUGED
// #define WANG
// #define XIA
using System;
using System.Diagnostics; // 为了使用包含在此名称空间中的ConditionalAttribute特性
namespace ConsoleTest
{
class ToolKit
{
[ConditionalAttribute( " WANG " )] // Attribute名称的长记法
[ConditionalAttribute( " BUGED " )]
public static void Method_1() { Console.WriteLine( " Created By WANG, Buged. " ); }
[ConditionalAttribute( " WANG " )]
[ConditionalAttribute( " NOBUG " )]
public static void Method_2() { Console.WriteLine( " Created By WANG, NoBug. " ); }
[Conditional( " XIA " )] // Attribute名称的短记法
[Conditional( " BUGED " )]
public static void Method_3() { Console.WriteLine( " Created By XIA, Buged. " ); }
[Conditional( " XIA " )]
[Conditional( " NOBUG " )]
public static void Method_4() { Console.WriteLine( " Created By XIA, NoBug. " ); }
}
class MClass
{
[STAThread]
static void Main( string [] args)
{
// 虽然方法都被调用了,但只有符合条件(有效宏)的才会被执行。
ToolKit.Method_1();
ToolKit.Method_2();
ToolKit.Method_3();
ToolKit.Method_4();
Console.ReadLine();
}
}
}