#117 – Use #define to Define a Symbol
October 12, 2010 2 Comments
In addition to defining symbols by specifying them in the project properties dialog (“conditional compilation symbols”), you can define symbols directly in your code using the #define directive. This is helpful when you want to have a conditional compilation symbol appear in some files, but not throughout the entire project.
Here’s an example. Note that the #define must be the first thing in the file.
#define LOGGING using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { #if LOGGING DoSomeLogging(); #endif uint x = 0x1234; } } }
I need to learn something on conditional compilation with C#.
Thank you Sean.
Take a look at posts #499 – #507. (Just go to the Index and then Ctrl+F in your browser to search for 499).