Need to use a compiler directive in C#

Posted on 2007-07-22
Last Modified: 2013-12-17

Back in my C++ days I could include or exclude lines of code depending on the program I wanted to build.  I simply coded aditional variable thet I either commented out or utilized.

Can I do this in C#??

I use Visual Studio 2006 Version 8.0.

Please tell me if it's possible and how to implement it.

Question by:newbieweb
    LVL 29

    Accepted Solution

    You can do what you want using preprocessor directives. Have a look

    Author Comment

    At first glance, it looks like what I used to do in C++.  But now I am wondering if that's what I actually need.

    I have a workiong program into which I integrated a web service.  But I am trying to run myprogram and a few other computers to process a large amount of data tonight.  But the web serice is not configured fro the extra machines and the guy who knows how to configure it won't be here until Monday.

    I'd rather use a switch that I can load from a database to turn the web service functionality on or off.

    I imagine I should not have any problem with this approach. Do you?

    LVL 29

    Expert Comment

    Definitely. I'd go for this approach. Just set a flag to use some functionality or not. Should be easy, definitely easier than recompiling and deploying.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now