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?
This question is related to
c#
visual-studio
console
visual-studio-2015
in the "Ouput Window". you can usually do CTRL-ALT-O to make it visible. Or through menus using View->Output.
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.
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".
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() .
Source: Stackoverflow.com