paddotk
paddotk

Reputation: 1438

Display simple test string/value

I'm new in Visual Studio (2015) and C# and am having trouble with something very basic. What I'm trying to do is to simply test a function by displaying some text, that indicates the function this is executed from is called. I'm making a WPF application.

I have experience with javascript, php and Actionscript 3/Flash, and in all these languages it's easy to simply write a line of text, to see whether a function is called or see the value of a variable; with something like trace(), console.write() etc.

However, after looking for hours to a simple way for do this in C#, I can't find any way to do this without writing whole blocks of code or having this text written to some external file.

To my understanding, Trace.WriteLine() writes its content to an external file and needs a whole bunch of additional lines of code to have it displayed somewhere else. Same for Console.WriteLine(), because you first have to summon the console to be opened first.

As for now, I'm using System.Windows.MessageBox.Show("test"), but this isn't very convenient in my opinion. I cannot imagine there is no other simple way to trace a simple string or var or something.

Please help this rookie out!

Upvotes: 0

Views: 118

Answers (2)

NoChance
NoChance

Reputation: 5762

You can use Console.WriteLine() or Debug.WriteLine(). For the later, if you don't see the output, check this post:Where does System.Diagnostics.Debug.Write output appear?.

For further examples on Debug.WriteLine(), see:DotNetPerls-Debug.

Upvotes: 0

Szabolcs Dézsi
Szabolcs Dézsi

Reputation: 8843

What you are looking for can be achieved with Debug.WriteLine.

It will display in the Output window of Visual Studio.

Upvotes: 1

Related Questions