简体   繁体   English

访问成员变量时在Visual Studio中设置断点C#

[英]Set breakpoint in Visual Studio when a member variable is accessed C#

在Visual Studio中为C#代码访问成员变量数据时,是否可以设置断点?

You can't achieve this for a regular field, because the debugger can not break on a simple memory copy operation. 对于常规字段,您无法实现此目的,因为调试器无法在简单的内存复制操作上中断。 However, let's say we have a field called UncleName , like so: 但是,假设我们有一个名为UncleName的字段,如下所示:

    public static string UnclesName = "Bob";

You could turn it into a property: 您可以将其变成一个属性:

    public static string _unclesName = "Bob";
    public static string UnclesName { get { return _unclesName; } set { _unclesName = value; } }

What really happens, is the compiler generates two methods for you under the hood, one to get the data from the field, and one to set it. 真正发生的是,编译器在后台为您生成了两种方法,一种是从现场获取数据,另一种是进行设置

The debugger can can break on methods, and since we have now changed our data to be accessed through a method, namely the UnclesName.get() method, we can insert a breakpoint on the get keyword of our property, and have the debugger break every time the data is accessed. 调试器可以中断方法,并且由于我们现在已经更改了要通过方法(即UnclesName.get()方法UnclesName.get()访问的数据,因此可以在属性的get关键字上插入一个断点,并使调试器中断每次访问数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果在Visual Studio和C#中,我可以在内联中设置断点吗? - Can I set a breakpoint in an inline if in Visual Studio and C#? 在Visual Studio中的C#通用类/方法上设置函数断点? - Set a Function Breakpoint on a C# Generic Class/Method in Visual Studio? 如何在Visual Studio 2013中的C#结构字段上设置断点 - How to set a breakpoint on a C# structure field in Visual Studio 2013 Visual Studio 2012 / C#中断了代码执行,没有设置断点 - Visual Studio 2012/C# breaks code execution, no breakpoint set Microsoft Visual Studio 2012无法在c#文件中设置断点 - Microsoft Visual Studio 2012 cannot set breakpoint in c# file 为什么Visual Studio无法在这个简单的C#属性上设置条件断点? - Why does Visual Studio fail to set a conditional breakpoint on this simple C# property? 在Visual Studio(C#)中进行脱胶时,是否可以在断点之后插入一行代码? - When doing degugs in Visual Studio(C#), Is there a way to insert a line of code after breakpoint? 调试C#时遇到Breakpoint时,防止显示Visual Studio窗口 - Prevent showing visual studio window when Breakpoint hits while debugging c# 应用程序仅在触发断点时挂起,即.NET,C#,Visual Studio - Application hangs only when breakpoint is triggered, .NET, C#, Visual Studio 当 Visual Studio 调试器评估值时,我可以让我的 C# 代码在断点处停止吗? - Can I make my C# code stop at breakpoint when Visual Studio debugger is evaluating the value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM