VS中定义的DEBUG常量

来源:互联网 发布:新网域名管理 编辑:程序博客网 时间:2024/06/07 00:06

            学习C#的过程中按照教程的描述自己敲了一段代码,具体如下:

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Threading.Tasks;

 

namespaceConsoleApplication4

{

    class Program

    {

        static void Main(string[] args)

        {

#if DEBUG

            Console.WriteLine("debug");

#else

            Console.WriteLine("non-debug");

#endif

        }

    }

}

            按照我自己的理解,这个应该是执行第二个输出语句。因为代码中我并没有通过预处理指令定义DEBUG。然而编译执行结果却与我考虑的不一致:


            这确实是有点费解,但是联想到了之前使用的基于eclipes的C开发环境,很多宏定义都是在配置选项中的。尝试查找了一下,果真找到了相应的信息:


            把项目属性中上面的信息勾掉再次测试,结果跟预期的一样。

原创粉丝点击