#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)
        {

#if LOGGING
            DoSomeLogging();
#endif
            uint x = 0x1234;
        }
    }
}

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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

Follow

Get every new post delivered to your Inbox.

Join 43 other followers