[英]How to define value for C# preprocessor symbol?
In C# one can define a preprocessor symbol like 在C#中,可以定义一个预处理程序符号,例如
#define DEBUG
How can I set a value, I wish to do something like this 我该如何设置一个值,我想做这样的事情
#define VERSION = "X.Y.Z"
Is it possible ? 可能吗 ? If yes how can I get its value ?
如果是,我如何获得其价值?
No, you cannot assign a value to a conditional compilation symbol but you can use conditionally defined constants. 不可以,您不能为条件编译符号分配值,但是可以使用条件定义的常量。
#define DEBUG
...
#if DEBUG
const string Version = "X.Y.Z";
#else
const string Version = "A.B.C";
#end if
As Victor said, C# doesn't have support for anything but boolean logic for #defines
. 就像Victor所说的那样,C#除了
#defines
布尔逻辑外不支持任何东西。
If you are looking for setting symbols from the project settings, use Resources (such as string resources) to do that. 如果要从项目设置中寻找设置符号,请使用资源(例如字符串资源)来完成。
If you are setting a version number of an application, the "Publish" tab of the project properties is one way of setting it. 如果要设置应用程序的版本号,则项目属性的“发布”选项卡是一种设置方式。 See this for a way to access it.
请参阅此以获取访问它的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.