我想知道发送使用#define 和#if 语句的实例。我知道它有一段时间了,但从未将它纳入我的编码方式。这究竟对编译有何影响?
Is #define the only thing that determines if the code is included when compiled? If I have #define DEBUGme as a custom symbol, the only way to exclude it from compile is to remove this #define statement?
最佳答案
在 C# 中,#define
宏,就像 Bernard 的一些例子,是不允许的。 C# 中 #define
/#if
的唯一常见用途是添加可选的仅调试代码。例如:
static void Main(string[] args)
{
#if DEBUG
//this only compiles if in DEBUG
Console.WriteLine("DEBUG")
#endif
#if !DEBUG
//this only compiles if not in DEBUG
Console.WriteLine("RELEASE")
#endif
//This always compiles
Console.ReadLine()
}
关于c# - 你如何使用#define?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15744/