C#中的预处理器指令 [英] Preprocessor directives in C#
本文介绍了C#中的预处理器指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中,如果预处理程序指令是在实际编译之前进行预处理的指令,那么为什么不在该程序中首先执行该指令?
In C#, if preprocessor directives are instructions pre-processed before actual compilation then why is it not executed first in this program?
static void Main(string[] args)
{
Program1.display();
Program2 p2 = new Program2();
p2.show();
#if DEBUG
Console.WriteLine("DEBUG from preprocessor directive is working!");
#endif
}
预期输出:
DEBUG from preprocessor directive is working!
.......(from display())
.......(from show())
但实际输出:
.......(from display())
.......(from show())
DEBUG from preprocessor directive is working!
推荐答案
您期望的输出是错误的.
The output you are expecting is wrong.
在 DEBUG
模式/配置下处理(待编译)的代码
Code processed (to be compiled) in DEBUG
mode/configuration
static void Main(string[] args)
{
Program1.display();
Program2 p2 = new Program2();
p2.show();
Console.WriteLine("DEBUG from preprocessor directive is working!");
}
以非- DEBUG
模式/配置处理(待编译)的代码
Code processed (to be compiled) in non-DEBUG
mode/configuration
static void Main(string[] args)
{
Program1.display();
Program2 p2 = new Program2();
p2.show();
}
希望这可以消除您的困惑,即预处理器不会决定执行顺序.
Hope this clears your confusion that preprocessors don't decide execution order.
这篇关于C#中的预处理器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文