Reputation: 9912
I have a question regarding debugging using Visual Studio.
We all know that when debugging you can set breakpoints and have some variables watched. These variables can be editted too. (So you can change their values) In the case you have a collection (that has for example two elements, you can see the elements and change their values)
But can you add or delete elements of that collection? Is there a way to do this from your watch window?
Upvotes: 1
Views: 3116
Reputation: 37367
You can also right click any variable, enter "Quick watch" and in expression text box evaluate expressions such as Add
method on a list.
Upvotes: 0
Reputation: 132
Yes, there is a way to add or delete elements when you are debugging. When you are in debug mode in Visual Studio, you can simply add the code you need like the way you do while writing code and debug. You can also watch values in watch window. (Its in Microsoft visual studio community 2017). If you are using visual studio 2015, I think there is a option to pause below menu bar while debugging to add extra code in debug mode.
Actually, you will not need watch window. You can simple add code in editor. Alternatively, there is Immediate window(ctrl + Alt + I) to check on that.
Upvotes: 0
Reputation: 1114
You can do this from the Immediate Window (Ctrl-Alt-I)
If I run this code and stop on a breakpoint right after this:
var list = new List<int>();
list.Add(1);
list.Add(2);
I can type list.Add(3)
in the Immediate Window (and press Enter to run it). If I then type ? list
(in the Immediate Window) and press Enter, it will show that the 3rd element has been added.
Upvotes: 7