且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在运行时观察变量?

更新时间:2023-02-15 12:55:29

当您的程序在断点处停止时,单击调试器菜单最右侧的图标(见下图).您可以在此窗口中输入方法或变量名称,然后查看它们会是什么.

When your program has stopped on a breakpoint click the icon at the far right of the debugger menu (see image below). You can type in methods or variable names into this window and see what they would be.

您可以输入您喜欢的任何表达式(只要它在您破坏代码的范围内)并输入任何硬编码的值或对象,而无需重新运行您的项目.

You can type any expression you like (as long as it is within the scope of where you broke your code) and input any hard-coded values or objects all without re-running your project.

将变量添加到您的观察列表

首先在类中要观察特定变量的位置放置一个断点.运行代码,一旦它从变量"窗口框架命中您的断点,您应该会看到所有可访问的变量.只需选择您想观看的内容,然后右键单击并从下拉列表中选择添加到观看".

Start by putting a break point in the class where you'd want to watch a specific variable. Run the code and once it hits your breakpoint from the Variables window frame you should see all of the variables that are accessible. Simply choose the one you'd want to watch and then right click and choose "Add to watches" from the drop-down.

继续调试,您应该会根据您的代码在适当的时候看到 Watches 窗口框架中的变量更新.

Keep debugging and you should see the variable from the Watches window frame update when appropriate based on your code.