你如何使用的#define? [英] How do you use #define?
问题描述
我想了解一下情况时,它使发送到使用#define和#如果语句。我已经知道这件事了一段时间,但从来没有将其纳入我的编码方式。正是这将如何影响编译?
时的#define,决定是否在编译时包含代码的唯一的事?如果我有#定义DEBUGme作为一个自定义符号,从编译排除它的唯一方法就是删除这个#define语句?
块引用>
解决方案在C#
的#define
宏,像一些伯纳德的例子,是不允许的。在C#中唯一的共同使用的#define
/的#如果
s是添加可选的调试唯一的代码。例如:静态无效的主要(字串[] args)
{
#如果DEBUG
//这只是编译如果DEBUG
Console.WriteLine(调试)
#ENDIF
#如果!DEBUG
//这只是编译如果不是在DEBUG
Console.WriteLine(发行)
#ENDIF
//这总是编译
到Console.ReadLine()
}
I'm wondering about instances when it makes sent to use #define and #if statements. I've known about it for a while, but never incorporated it into my way of coding. How exactly does this affect the compilation?
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?
解决方案In C#
#define
macros, like some of Bernard's examples, are not allowed. The only common use of#define
/#if
s in C# is for adding optional debug only code. For example: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() }
这篇关于你如何使用的#define?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!