#define MYTEST
#define DEBUG

using System;
using System.Collections.Generic;
using System.Text;

namespace PreprocessorDirectives
{
class Program
{
static void Main( string[] args )
{
#if (DEBUG && !MYTEST)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
Console.WriteLine( "DEBUG and MYTEST are defined" );
#else
Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
}
}
}

代码是从msdn上copy的,问题是我怎么才能让最后一句Console.WriteLine("DEBUG and MYTEST are not defined");执行呢?我试过把#define MYTEST #define DEBUG这两行注释掉都不行啊



C#中,预编译符不是写上就可以的,你还需要在项目属性里面build,条件编译符号里面定义上你这个MYTEST才行,这个需要两个步骤

http://zhidao.baidu.com/link?url=Yo04iwUE4zzzpHj4KASrP2omISANDN68g_NfjMVrrcJWyLQX_dc1ddi0l5QDR1JdNvcuDtMdJos5iW2U7dmzuK