用到预处理指令了就查阅msdn学习并参照例子练习了下。暂时先记录下遇到的问题。
1。预处理指令不预先定义
debug模式下#debug 则一直为true即使注释掉也能使用其他预处理指令如果不预先声明,直接判断结果不出错但是判断结果为false
2.在release下 Console.WriteLine函数无法使用
#define DEBUG
#define VC_V7
using System;
public class MyClass
{
static void Main()
{
#if (DEBUG && !VC_V7)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && VC_V7)
Console.WriteLine("VC_V7 is defined");
#elif (DEBUG && VC_V7)
Console.WriteLine("DEBUG and VC_V7 are defined");
#else
Console.WriteLine("DEBUG and VC_V7 are not defined");//在release模式下 这里会编译错误
#endif
}
}
但是同样类型用#if #else #endif就可以通过?如下
#if (xx)
Console.WriteLine("xx defined");
#else
Console.WriteLine("xx not defined");
#endif
但是此段代码无论在debug还是release下都能正常执行 同样在未预先定义预处理指令