I once saw the source code of a winform
application and the code had a Console.WriteLine();
. I asked the reason for that and i was told that it was for debugging purposes.
Pls what is the essence of Console.WriteLine();
in a winform
and what action does it perform because when i tried using it, it never wrote anything.
Winforms are just console apps that show windows. You can direct your debug info to the console app.
As you can see in the below example there is a command that attaches the parent window then pumps info to it.
Here is the resource for this example:http://www.csharp411.com/console-output-from-winforms-application/
You wouldn't really use it normally but if you've attached a Console or use AllocConsole, it will function like in any other console application and the output will be visible there.
For quick debugging, I prefer
Debug.WriteLine
but for a more robust solution, the Trace class may be preferable.It wouldn't perform anything unless theReally, they should be leveragingConsole
was redirected to say theOutput
window.Debug.WriteLine
instead.The benefit of
Debug.WriteLine
is that it gets optimized away when building inRelease
mode.NOTE: as pointed out by Brad Christie and Haedrian, apparently it will in fact write to the
Console
window in Visual Studio when running a Windows Forms application. You learn something new every day!It writes to the Console.
The end user won't see it, and to be honest its much cleaner to put it into a proper log, but if you run it through VS the Console window will populate.