I know I can conditionally set variables by conditionally including code like so:
#if DEBUG
someVar = "foo";
#else
someVar = "bar";
#endif
I would rather enumerate or test for compiler constants at runtime.
For example, I want to put all of the symbols defined at compile time in a window title so that testers can see which build they are testing.
I think the preprocessor removes the unused code at compilation time.
But you can accomplish the same thing in a cleaner way using conditional attributes:
[Conditional("DEBUG")]
public void DrawDebugTitle() {
Form1.Title = "Debug mode";
}
Then simply call the method normally, and if DEBUG is defined then it will change the form's title, and if DEBUG isn't defined then the method call, while still appearing in your code, will do nothing.