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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #define LOGGINGusing 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; } }} |

