Visual Studio 中的条件断点

发布于 2024-08-22 18:10:08 字数 207 浏览 19 评论 0原文

当其他变量等于特定值时,我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

淡写薰衣草的香 2024-08-29 18:10:08

<代码>
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

邮友 2024-08-29 18:10:08

示例代码:

static void Main(string[] args) {
  string myvar;
  for (int ix = 0; ix < 10; ++ix) {
    if (ix == 5) myvar = "bar"; else myvar = "foo";
  }    // <=== Set breakpoint here
}

条件:myvar == "bar"

效果很好。

Sample code:

static void Main(string[] args) {
  string myvar;
  for (int ix = 0; ix < 10; ++ix) {
    if (ix == 5) myvar = "bar"; else myvar = "foo";
  }    // <=== Set breakpoint here
}

Condition: myvar == "bar"

Works well.

吃→可爱长大的 2024-08-29 18:10:08

就像在代码中一样,您需要使用:

MyStringVariable == "LKOH"

双等号是关键。如果没有它,它会说它无法计算,因为您的表达式不会计算为布尔值。

Just like in code, you need to use:

MyStringVariable == "LKOH"

The double-equals is the key. Without it, it's saying it can't evaluate because your expression doesn't evaluate to a boolean.

清引 2024-08-29 18:10:08

你应该能够完成这项工作。您是否在条件中使用 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" not Exchange.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.

失退 2024-08-29 18:10:08

就我而言,我忘记了我正在调试 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 be myString = "someValue" not myString == "someValue"

囚你心 2024-08-29 18:10:08

您正在测试的变量需要位于断点的范围内。

var x = "xxx";
{ 
  var y = "yyy";
}

brak(); // x is in scope, y isn't

The variable you are testing for needs to be in scope at the breakpoint.

var x = "xxx";
{ 
  var y = "yyy";
}

brak(); // x is in scope, y isn't
柠北森屋 2024-08-29 18:10:08

对我来说,这使它达到了条件断点。

条件断点

For me this made it hit the conditional breakpoint.

Conditional breakpoint

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文