Visual Studio 中的条件断点
当其他变量等于特定值时,我想在 C# 代码中的某一行设置断点,例如:
MyStringVariable == "LKOH"
我该怎么做?
我尝试右键单击断点图标 ->条件,然后输入 MyStringVariable == "LKOH"
,Visual Studio 表示无法对其求值。
I want to set a breakpoint on a certain line in C# code when some other variable is equal to a specific value, say:
MyStringVariable == "LKOH"
How can I do that?
I tried to right click on breakpoint icon -> Condition and then typed MyStringVariable == "LKOH"
and Visual Studio said it cannot evaluate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
<代码>
if (MyStringVariable == "LKOH") Debugger.Break();
你需要 System.Diagnostics 命名空间
http ://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
if (MyStringVariable == "LKOH") Debugger.Break();
you'll need System.Diagnostics namespace
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
示例代码:
条件:myvar == "bar"
效果很好。
Sample code:
Condition: myvar == "bar"
Works well.
就像在代码中一样,您需要使用:
双等号是关键。如果没有它,它会说它无法计算,因为您的表达式不会计算为布尔值。
Just like in code, you need to use:
The double-equals is the key. Without it, it's saying it can't evaluate because your expression doesn't evaluate to a boolean.
你应该能够完成这项工作。您是否在条件中使用 Exchange 实例名称?条件应该类似于
myExchange.Name == "LKOH"
而不是Exchange.Name == "LKOH"
。顺便说一下,使用赋值运算符
=
而不是等于运算符==
可以,但它会设置属性并浪费 1/2 小时的时间来弄清楚什么地狱正在发生。我昨天就犯了这个错误。You should be able to make this work. Are you using the Exchange instance name in the condition? The condition should be something like
myExchange.Name == "LKOH"
notExchange.Name == "LKOH"
.By the way, using the assignment operator
=
instead of the equality operator==
will work but it will set the property and waste 1/2 hour of your time figuring out what the hell is going on. I made this mistake just yesterday.就我而言,我忘记了我正在调试 VB 应用程序。
在 VB 中,等式是
=
,而不是像许多其他语言那样==
,因此我的条件断点需要是myString = "someValue"
而不是myString ==“someValue”
In my case, I forgot that I was debugging a VB application.
In VB equality is
=
not==
like many other languages, thus my conditional breakpoint needed to bemyString = "someValue"
notmyString == "someValue"
您正在测试的变量需要位于断点的范围内。
The variable you are testing for needs to be in scope at the breakpoint.
对我来说,这使它达到了条件断点。
For me this made it hit the conditional breakpoint.