Visual studio equivalent of java System.out

C#Visual Studio-2010Debugging

C# Problem Overview


What do I use in Visual Studio (C#) to perform the equivalent of Java's System.out.println( /*stuff*/ ) ?

Does the output from the command show in the Output window in the IDE?

I have a button on a webpage that calls a service which returns a string. I want to see what's in the string and have tried all the variations below and nothing ever shows up in the output. It also doesn't stop on the breakpoint so I can check if there are any results.

var service = new OTest.TylerAPI.APIWebServiceSoapClient();
results = service.OdysseyMsgExecution("<Message MessageType='FindCaseByCaseNumber' Source='APIMessage' ReferenceNumber='1' NodeID='1' UserID='1'> <CaseNumber>T4CV0043212010</CaseNumber></Message>", "NMODYSSEYMETRO");
System.Diagnostics.Debug.Write(results);

C# Solutions


Solution 1 - C#

Try: Console.WriteLine (type out for a Visual Studio or Rider snippet)

Console.WriteLine(stuff);

Another way is to use System.Diagnostics.Debug.WriteLine:

System.Diagnostics.Debug.WriteLine(stuff);

Debug.WriteLine may suit better for Output window in IDE because it will be rendered for both Console and Windows applications. Whereas Console.WriteLine won't be rendered in Output window but only in the Console itself in case of Console Application type.

Another difference is that Debug.WriteLine will not print anything in Release configuration.

Solution 2 - C#

Use Either Debug.WriteLine() or Trace.WriteLine(). If in release mode, only the latter will appear in the output window, in debug mode, both will.

Solution 3 - C#

In System.Diagnostics,

Debug.Write()
Debug.WriteLine()

etc. will print to the Output window in VS.

Solution 4 - C#

Or, if you want to see output in the Output window of Visual Studio, System.Diagnostics.Debug.WriteLine(stuff)

Solution 5 - C#

You can use Console.WriteLine() to write out any native type. To see the output you must write console application (like in Java), then the output will be displayed in the Command Prompt, or if you are developing a windows GUI application, in Visual Studio you must turn on "Output" panel (under View) to see the commands output.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeslieView Question on Stackoverflow
Solution 1 - C#nanView Answer on Stackoverflow
Solution 2 - C#FemarefView Answer on Stackoverflow
Solution 3 - C#3DaveView Answer on Stackoverflow
Solution 4 - C#Adam MarasView Answer on Stackoverflow
Solution 5 - C#CipiView Answer on Stackoverflow