.netvisual-studiodebuggingbreakpointsconditional-breakpoint

Can I set a breakpoint when variable is getting a specific value in .NET?


I am using Visual Studio 2010, and I know this feature is available in C++.

I need to debug some code, that changes a variable to several values. I want to debug the code in a specific case, when the variable getting a specific value. I know I can add if(var == value), but is there any elegant way to do it?

Another question, can I set a breakpoint when a variable is changed in general?


Solution

  • It is certainly possible to set a condition like a variable receiving a certain value. This is known as a breakpoint condition. To create one, do the following.

    Now the breakpoint will only hit when your conditional evaluates to true.

    The second item you asked for, breaking when a variable's value changes for any reason, is known as a data breakpoint. These are only available for C++ code. It's not an option in C#, VB.NET or any other managed language.