I'm new to C# and VS and I'm just trying to print a line using Console.WriteLine(...) but it only shows up in the command prompt. Is there a way to make output show in the output window instead?
EDIT: It's a console application.
Also, how do I access the command line in order to run programs? I've only been able to figure out how to run with F5, but this won't work if I need to type in arguments.
Yes I ran into this problem too, my first 2 days with VS2012. Where is my console output? it flashes and disappears. Mystified by usefull examples like
https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
Ok, indeed @martynaspikunas .. trick you can replace Console.WriteLine() by Debug.WriteLine() to see it in the IDE. It will stay there, nice.
But sometimes you have to change a lot of places in existing code to do that.
I did find a few alternatives.. How about a single
in Program.cs ? The console will wait for you, it can scroll..
I also like to use the Console output in my Winforms contexts:
Add this class after your main form class. Then plug it in, using the following redirect statement in the constructor, after InitializeComponent() is called:
As a result of this, all your Console.WriteLine() will appear in the richTextBox.
Sometimes I use it to redirect to a List to report Console later, or dump it to a textfile.
Note: the MyLogger code snippet was put here by Hans Passant in 2010,
Bind Console Output to RichEdit
Here is a simple trick to keep the console and its output:
If it's a ConsoleApplication then
Console.WriteLine
will write the console. If you useDebug.Print
, it will print to the Output tab at the bottom.If you want to add command line arguments, this can be found in the project properties. Click
Project -> [YourProjectName] Properties... -> Debug -> Start Options -> Command line arguments
. The text here will be passed to your application when it's run. You can also run it after it's built by running it out of thebin\Release
orbin\Debug
folder after you build it, throughcmd
or however you prefer. I find it easier to test various parameters this way rather than setting the command line arguments each time.