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 8174273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:24:35+00:00 2026-06-06T22:24:35+00:00

I use a lot of lines like that Console.WriteLine(Test); to debug application under VS

  • 0

I use a lot of lines like that

Console.WriteLine("Test");

to debug application under VS 2010.

My question is: Have I do comment all those lines when I build an application?

Thanks!

  • 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-06-06T22:24:37+00:00Added an answer on June 6, 2026 at 10:24 pm

    Yes. In fact, if your app was a console application, you’d really want those lines executed. Have a look at System.Diagnostics.Debug methods (e.g. Debug.WriteLine) which may be what you need. Their output is in Visual Studio’s Output window, and they do nothing in Release code.

    More generally, you can have code that’s only compiled in a Debug build by doing:

    #if DEBUG
    // Debug-only code here.
    #endif
    

    You can also put this attribute before your method definition to write a method that’s not called at all when you do a Release build:

        [System.Diagnostics.Conditional("DEBUG")]
    

    All these methods have the advantage that they shouldn’t affect the performance of production code.

    To check I’m giving you accurate advice, I compiled the following in Release mode:

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world!");
    
    #if DEBUG
            Console.WriteLine("Inside #if block.");
    #endif
    
            WriteLine("With ConditionalAttribute.");
    
            Debug.WriteLine("Debug.WriteLine.");
        }
    
        [Conditional("DEBUG")]
        public static void WriteLine(string line)
        {
            Console.WriteLine(line);
        }
    }
    

    I then used the IL Dissasembler tool to see what will actually run:

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       11 (0xb)
      .maxstack  8
      IL_0000:  ldstr      "Hello world!"
      IL_0005:  call       void [mscorlib]System.Console::WriteLine(string)
      IL_000a:  ret
    } // end of method Program::Main
    

    As you can see, only the Console.WriteLine method is called. The other three alternatives are, as we had hoped, ‘compiled out’ of the debug code.

    The Debug version looks like this:

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       46 (0x2e)
      .maxstack  8
      IL_0000:  nop
      IL_0001:  ldstr      "Hello world!"
      IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
      IL_000b:  nop
      IL_000c:  ldstr      "Inside #if block."
      IL_0011:  call       void [mscorlib]System.Console::WriteLine(string)
      IL_0016:  nop
      IL_0017:  ldstr      "With ConditionalAttribute."
      IL_001c:  call       void ConditionalCompileTest.Program::WriteLine(string)
      IL_0021:  nop
      IL_0022:  ldstr      "Debug.WriteLine."
      IL_0027:  call       void [System]System.Diagnostics.Debug::WriteLine(string)
      IL_002c:  nop
      IL_002d:  ret
    } // end of method Program::Main
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of lines like this in my program, Current[0][1] - CILH.Offset;
I have a file with a lot of lines like this: 1:458:187:131 1:1124:384:63 1:2300:514:31
After quite a lot of experimentation, I think that I like: (setq truncate-lines nil)
I would like your help with something that I have searched a lot but
I use $_SERVER[DOCUMENT_ROOT] a lot to make sure that all my links will work
I have a bizarre problem. I use a lot of session variables so I
I am writing a client-side .NET application which is expected to use a lot
I have learned to use Lua a lot of the time and I also
i have a quite weird question which probably has no practical use but the
I have command-line program that do a lot of work and produce a lot

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.