IR GenericPerson
IR GenericPerson

Reputation: 7

How to output value of var when debugging in Visual Studio

I am new to Visual Studio and have a question related to debugging.

I set a debugging breakpoint which has led me to a line that I need for the XML object values. In this case it just called objectToSend(see below). If I highlight the line when debugging I can see the value pairs for the object but is there a way to easily copy the values? I've tried to right click thinking there would be an option there but the "copy" just gets the current var not the whole object.

var data = ToXml(objectToSend);

Sorry for such and easy question, I'm trying to learn how to debug in VS.

Thank you very much for your time and assistance, I appreciate it very much!!

Upvotes: 0

Views: 150

Answers (1)

Gene
Gene

Reputation: 4232

To print a variable and all of its members, you can use the Immediate Window. Just set your breakpoint and enter the name of the variable when the breakpoint is hit. For the following code:

var kv = new Dictionary<string, string>();
kv.Add("one", "1");
kv.Add("two", "2");    

the Immediate Window will print the following text when entering kv:

kv
Count = 2
  [0]: {[one, 1]}
  [1]: {[two, 2]}

Upvotes: 1

Related Questions