Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:59:22+00:00 2026-05-12T17:59:22+00:00

Sorry for the extreme newbie question, but I couldn’t find the answer elsewhere and

  • 0

Sorry for the extreme newbie question, but I couldn’t find the answer elsewhere and haven’t actually ever done anything like this myself (go figure — I guess that happens when your company uses the production environment for testing).

It would be nice if Visual Studio offered some mechanism for specifying that certain segments of code (e.g., logging) should only be included in the Debug build. Does this exist? I’m interested in methods for this in both C# and VB.NET, and on VS 2005, in case that matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:59:23+00:00Added an answer on May 12, 2026 at 5:59 pm

    There are several ways.

    To mark a specific section of your code to only be included in Debug builds, you can do this in C#:

    #if DEBUG
        code that will only compile for Debug
    #endif
    

    If you want to avoid this, you can tag methods with an attribute:

    [Conditional("DEBUG")]
    public void Log(String message) { ... }
    

    In this case, calls to this method will be automagically stripped out of your compiled code if you’re not compiling for Debug. There are limitations to this. For instance, if you use ref or out parameters, or return values, then you can’t use this.

    You can read more about the #if directive here: C# Preprocessor Directives, and the attribute here: ConditionalAttribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for question but I can't find answer anywhere on internet. I couldn't find
sorry for the dummy question but I cannot find a simple and clean way
Sorry if it was already asked before, but I really couldn't find a clear
Sorry if this is a newbie question. I can't seem to find a response
Sorry if this question's been asked before, but I can't seem to find an
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this is a stupid question, but is there an easy way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.