How do I find Console.WriteLine() values when I have no console? Or How do I print out values at run-time with no Console.

StackOverflow https://stackoverflow.com/questions/19371095

  •  30-06-2022
  •  | 
  •  

Pregunta

I am sure there is an answer to this somewhere, alas I am too much of a Noob to know exactly what to ask. I have been studying Computer Science since January of this year, and coming from Python to C# has caused me to think of everything in "pythonic" terms. I am taking a class on Coursera.org (Colorado state class by Tim A.) called "Beginning Game Programming with C#" I am using XNA game studio and so there is no Console.WriteLine available.

From my extremely limited working knowledge (<= 6 months Python, ~1.5 months C#), is there a way to write out values akin to a Console.WriteLine, when you are not working on a console application? How do you "dynamically" print values in C#? Is there even a way. In Python you can simply type "Print X" in the interpreter or in the editor and it will print the value. Is there an equivalent in C#? Now I know of Console.WriteLine() and Messagebox.Show() but I am working in XNA game studio and I cannot use them. Console.WriteLine doesn't seem to do anything, and MBox doesn't even let me use System.Windows namespace. Is there a way to get a copy of the Console.WriteLine even though it didn't show up in my game window?

There is windows in Visual Studio that like "immediate window" and "Watch" that I have never seen used. Is there a way to write out a value to one of these windows during runtime so that I can see or use it? This is just a guess.

¿Fue útil?

Solución

use

System.Diagnostics.Trace.WriteLine("I'm adding the cost of this answer to your tab.");

The System.Diagnostics.Debug class provides a set of methods and properties that help debug code. The System.Diagnostics.Debug.Write and System.Diagnostics.Debug.WriteLine methods can be used to send text to the debug output window. The debug output window can be displayed by selecting View - Other Windows - Output in the Visual Studio .NET menu. The debug output can only be viewed in this window if the debugger is attached to the process that is writing to the output window. source: http://msdn.microsoft.com/en-us/library/ms698739%28v=vs.85%29.aspx

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top