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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Yes. In fact, if your app was a console application, you’d really want those lines executed. Have a look at
System.Diagnostics.Debugmethods (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:
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:
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:
I then used the IL Dissasembler tool to see what will actually run:
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: