如何定义一个全局常量在C#中(如DEBUG) [英] How to define a constant globally in C# (like DEBUG)
本文介绍了如何定义一个全局常量在C#中(如DEBUG)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想不同的编译项目,根据的#define定义的常数,是这样的:
I want to compile a project differently, according to a constant defined by #define, like this:
#define USE_COMPONENT_X
#if USE_COMPONENT_X
...
#endif
和我能做到这一点在C#。但是,当我去同一个项目的另一个文件,这个常量没有定义。我能以某种方式定义常量的所有项目,如DEBUG被定义呢?
and I can do that in C#. But when I go to another file in the same project, this constant is not defined. Can I in some way define a constant to all the project, like DEBUG is defined so?
推荐答案
您可以添加/定义编译器开关。
You can add the /define compiler switch.
- 打开项目的属性页对话框。
- 单击配置属性文件夹。
- 点击生成属性页。
- 修改条件编译常量属性。
这篇关于如何定义一个全局常量在C#中(如DEBUG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文