Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Console.Writeline, Console.Write work in Visual Studio Express?

I just open a console application and I type

Console.WriteLine("Test");

But the output window doesn't show this. I go to the output window with Ctrl + W, O.

But nothing shows up when I run my program. Am I nuts or is this not supported in Visual Studio 2010 Express?

like image 346
Shai UI Avatar asked Dec 19 '10 00:12

Shai UI


People also ask

Where does console WriteLine write to in Visual Studio?

WriteLine() does not write to any window in Visual Studio. I guess it will only write to the application console if your application creates a console in the first place, i.e. if it is a console application. You could prefix your message with a string, e.g. ">>>" and use VSColorOutpu to highlight such lines.

Where does console WriteLine write to in C#?

First, Console. WriteLine() writes to the standard output stream which can be read by attaching a console window or through other means of intercepting the stream. Then, to send your output to a file you could setup a TraceListener which could be a file or something.

What is the difference between console WriteLine () and console write ()?

The only difference between the Write() and WriteLine() is that Console. Write is used to print data without printing the new line, while Console. WriteLine is used to print data along with printing the new line.


14 Answers

Console.WriteLine writes your output to the console window opened by your application (think black window with white text that appears when you open the Command Prompt.) Try System.Diagnostics.Debug.WriteLine instead.

like image 68
Adam Maras Avatar answered Oct 03 '22 21:10

Adam Maras


No satisfactory answers were provided.

System.Diagnostics.Debug.WriteLine() will write messages to the Output:debug window, but so much crap is constantly dumped into that window by every process under the sun, it is like finding a needle in a haystack to find your messages.

Console.WriteLine() does not write to any window in Visual Studio. I guess it will only write to the application console if your application creates a console in the first place, i.e. if it is a console application.

like image 39
Paul Gorbas Avatar answered Oct 03 '22 19:10

Paul Gorbas


Go to properties in you own project in the Solution Explorer window and choose application type and look for Output Type.

Change its value to Console Application.

This will make console screen besides your form. If you close the console screen, your form will be closed too.

like image 44
ibrahim Avatar answered Oct 03 '22 19:10

ibrahim


Perhaps the console is clearing. Try:

Console.WriteLine("Test");
Console.ReadLine();

And it will hopefully stay there until you press enter.

like image 37
Leif Andersen Avatar answered Oct 03 '22 19:10

Leif Andersen


Or you can debug by CTRL+F5 this will open ConsoleWindow waits after last line executed untill you press key.

like image 34
Javed Akram Avatar answered Oct 03 '22 20:10

Javed Akram


It's more than likely because you've used Console in the namespace. For example like this:

namespace XYZApplication.Console
{
    class Program
    {
        static void Main(string[] args)
       {
            //Some code;             
       }
    }
}

Try removing it from the namespace or use the full namespace instead i.e.

   System.Console.Writeline("abc");
like image 30
nadsy Avatar answered Oct 03 '22 19:10

nadsy


The output window isn't the console. Try the methods in System.Diagnostics.Debug

like image 32
lesscode Avatar answered Oct 03 '22 19:10

lesscode


Try Ctrl + F5. It will hold your screen until you press any key.

like image 36
Sumen Kr Mallick Avatar answered Oct 03 '22 20:10

Sumen Kr Mallick


In a Windows Forms application, both methods,

System.Diagnostics.Debug.WriteLine("my string")

and

System.Console.WriteLine("my string")

write to the output window.

In an ASP.NET Core application, only System.Diagnostics.Debug.WriteLine("my string") writes to the output window.

like image 27
user6849960 Avatar answered Oct 03 '22 19:10

user6849960


I run into a similar problem while running a unit test. Console.WriteLine() did not write anything into the Visual Studio Output Window.

Using System.Diagnostics.Debug.WriteLine() solved the problem.

like image 41
Peter Huber Avatar answered Oct 03 '22 21:10

Peter Huber


None of the answers here worked for me!! Most of these people here are stuck in Windows Desktop Application Consoleland. If you are a web developer using ASP.NET in Visual Studio and do not see any console or debug text, here is how to fix that:

  1. Paste the following two tests into your code so it runs both lines. These are tests for the output window:

    System.Console.WriteLine($"hello console!");

    System.Diagnostics.Debug.WriteLine($"hello debugger!");

  2. In Visual Studio choose VIEW > OUTPUT. You will see the results above in this output window after changing two settings below.

  3. When NOT DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "YourProjectName - ASP.NET CORE Web Server". Run your code. You should see the "Console" text above.

  4. When DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "Debugger". Run your code in debug mode. You should see the "Debug" text above.

like image 39
Stokely Avatar answered Oct 03 '22 19:10

Stokely


Right click on the project in Solution Explorer and click "Clean".

Now run - press F5.

Make sure the code is as below:

Console.WriteLine("TEST");
Console.ReadLine();
like image 34
akash Avatar answered Oct 03 '22 21:10

akash


If you use Ctrl-F5 (start without debugging) it will leave the console window open with a message "Press any key to continue". That's the easiest way to keep the console window from closing so you can see the console output.

like image 25
Jeffrey Counts Avatar answered Oct 03 '22 20:10

Jeffrey Counts


Go to the Debug menu and select Options and uncheck "Redirect all Output Window text to Immediate Window"

like image 32
user241636 Avatar answered Oct 03 '22 21:10

user241636