I am new to C# and downloaded the free version of Microsoft Visual Studio 2015. To write a first program, I created a Windows Forms Application. Now I use Console.Out.WriteLine()
to print some test data. But where can I read the console?

- 1,145
- 1
- 12
- 29
-
Maybe [this](http://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application) can help? – Estiny Nov 12 '15 at 11:06
-
I really wish if Visual Studio had an integrated shell terminal within Visual Studio itself from where I can also read and capture user input like we do in case of console applications. It is already supported in [Visual Studio Code](https://stackoverflow.com/q/43427631/465053) – RBT Jun 16 '18 at 07:32
7 Answers
The simple way is using System.Diagnostics.Debug.WriteLine()
Your can then read what you're writing to the output by clicking the menu "DEBUG" -> "Windows" -> "Output".

- 79,749
- 26
- 255
- 305

- 1,890
- 1
- 10
- 9
-
4Quite Useful, and to make it simple, if you add the namespace `using System.Diagnostics;` then all you need to write is `Debug.WriteLine();` , beautiful alternative to `Console.WriteLine();`, without need of creating a new Console app.. – Irf Dec 21 '16 at 09:15
-
Coming from a Javascript background, the console is used to print everything. Is this not the case in .NET? What is 'specific' about a console application that it will only print to a text terminal and will be ignored by Visual Studio output? – Zach Smith Dec 22 '16 at 07:40
-
2@ZachSmith It's different because by default in VS, programs aren't necessarily running attached to "the console." Instead, they will usually launch their own console instance. If you use the debug console mentioned here, this won't happen and the built-in console will be used instead. In Node.js, the default console IS the built-in one usually. – the_endian Mar 14 '17 at 18:06
-
I know this one's old, but @Irfan 's comment saves you keystrokes, but `using static System.Diagnostics.Debug` saves you even more if you don't need `Console.WriteLine` – TheDoc May 09 '18 at 19:57
-
Do I need to be in **Debug** mode (F5) or can I be in **Build** mode (ctrl + f5)? – Web Developer Apr 07 '21 at 15:12
-
1
in the "Ouput Window". you can usually do CTRL-ALT-O to make it visible. Or through menus using View->Output.

- 634
- 6
- 16
You can run your program by: Debug -> Start Without Debugging
. It will keep a console opened after the program will be finished.

- 5,056
- 9
- 62
- 136
What may be happening is that your console is closing before you get a chance to see the output. I would add Console.ReadLine();
after your Console.WriteLine("Hello World");
so your code would look something like this:
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.ReadLine();
}
This way, the console will display "Hello World" and a blinking cursor underneath. The Console.ReadLine();
is the key here, the program waits for the users input before closing the console window.

- 640
- 5
- 6
-
1I needed to debug a console app whilst checking the existing output & without changing everything, so I wrapped `Console.ReadLine();` in `#if DEBUG` and this was the perfect answer! – SharpC Sep 10 '20 at 12:19
-
I agree with @SharpC. I'm using Visual Studio 2019 and experiencing the same thing. After adding `Console.ReadLine();` to my code, I was able to see everything I was trying to write to the console. Excellent tip! – Lou Feb 25 '22 at 15:24
You should use Console.ReadLine() if you want to read some input from the console.
To see your code running in Console:
In Solution Explorer (View - Solution Explorer from the menu), right click on your project, select Open Folder in File Explorer, to find where your project path is.
Supposedly the path is C:\code\myProj .
Open the Command Prompt app in Windows.
Change to your folder path. cd C:\code\myProj
Change to the debug folder, where you should find your program executable. cd bin\debug
Run your program executable, it should end in .exe extension.
Example:
myproj.exe
You should see what you output in Console.Out.WriteLine() .

- 48,840
- 22
- 240
- 204