#117 – Use #define to Define a Symbol

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)

            uint x = 0x1234;

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #117 – Use #define to Define a Symbol

  1. kai zhou says:

    I need to learn something on conditional compilation with C#.
    Thank you Sean.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: