Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define value for C# preprocessor symbol?

Tags:

c#

In C# one can define a preprocessor symbol like

#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 ?

like image 494
user310291 Avatar asked Aug 09 '26 21:08

user310291


2 Answers

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
like image 114
Victor Hurdugaci Avatar answered Aug 11 '26 11:08

Victor Hurdugaci


As Victor said, C# doesn't have support for anything but boolean logic for #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.

like image 29
Mark Lakata Avatar answered Aug 11 '26 11:08

Mark Lakata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!