Captain Comic Captain Comic - 1 year ago 129
C# Question

Conditional breakpoint in 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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download