Does anybody have any idea on how to do VB's debug.print in C#?
Printable View
Does anybody have any idea on how to do VB's debug.print in C#?
Nevermind I figured it out.
Please provide your answer. This way others who ask the same question can find the answer as well.
Sorry, inlude System.Diagnostics, then use Debug.Write to send output to the debug window, not the immediate window.
erm :rolleyes: you dont need to use System.Diagnostics , the correct equivalent to Debug.Print in .net / C# is this :
VB Code:
Console.Write("some stuff!");
You can use Debug.Print. The out put will be in the debug window.
That's actually not true at all.
Debug.Print in VB prints to the Immediate Window in VS. Console.Print does not. It either prints to a console if it's a console app or to the output window.
To be technical, Debug.Print will do TraceInternal.WriteLine which will write to each TraceListener that has been loaded into Listeners.
Console.Write calls Out.Write which writes to a TextWriter object.
The correct C# equivalent of VB.Net's Debug.Print is....
Debug.Print
And for the record, Debug.Print and Debug.Write are equivalent inasmuch as where they write. Debug.Write just doesn't add the newline character. And they all print to the Immediate Window, which is the same as VB6.
There are a couple of differences between Console methods and Debug methods that haven't been mentioned. If you call Console.WriteLine then the output will be written immediately and in both Debug and Release builds. Debug.WriteLine may not write immediately and any Debug code is not compiled into a Release build. Also, both Debug and Console write to the Output window on my system, which I think is an option somewhere.