How can I add variables to the Watch window

夙愿已清 提交于 2019-12-11 08:05:50

问题


Visual Studio 2008 Pro: Ok! from the Customize section I added the toolbar commands for Watch,QuickWatch,...to the Debug menu but I want to carefully watch one variable. How do we add it to the Watch? I highlight it and try to add it but it is disabled. I want to be able to first adding some variables of interest to the watch and then start debugging the program.


回答1:


You need to be in debugging in order to add variables to the Watch Window.

When debugging, you can just right click a variable and choose to add it to the watch.




回答2:


You will be able to add, view and remove variables from the Watch Mode when you are running under the debugger and execution is paused. The easiest way to get into such a state:

  1. Open your project in Visual Studio
  2. Set a breakpoint in the code within the scope of a variable you'd like to watch. Make sure that the code branch you're breaking on will be executed.
  3. Hit F5 or go to Debug > Start Debugging
  4. When the breakpoint is hit, add your variable to the watch window in any of the following ways:
    • Right click on the variable in code, and select "Add Watch"
    • Right click on the variable in the "Locals" windows, and select "Add Watch"
    • Type the variable name into a new row in the Watch pane itself.

Afterwards, you should see the variable name and value in the watch pane. The value will be updated as you step through the code and any time you pause execution or hit a breakpoint.



来源:https://stackoverflow.com/questions/5318663/how-can-i-add-variables-to-the-watch-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!