24.3. The /define compiler option and #undef

Instead of defining a symbol using the #define directive, you can define symbols by passing them in as compiler options. [3] If you are using csc.exe, you can pass in defined symbols like this:

[3] This is extremely useful. You would not want to keep commenting and uncommenting your #define directives, although they are usually conveniently located near the top of the source file.

c:\expt>csc /define:DEBUG,SHOW_ON_CONSOLE test.cs

You can use the short form /d: instead of /define:. Symbols to be defined are separated by commas (with no spaces between). Remember that symbols are case sensitive. If your #if directives are expecting the DEBUG symbol, passing in debug (lower case) via the /define option ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.