Question

Env: Visual Studio 2008 - C#

I have a for which runs for 1000+ times over a string array.

I want to have my app break when one of the strings matches a certain term so I can walk through at that point in my code.

Now I know I can add a piece of code that looks for this and a break point when it hits, but is there not a way to do this in the debugger?

Was it helpful?

Solution

Go to your code

  1. create a breakpoint
  2. right click on the red dot on the left
  3. select condition
  4. put something like i == 1000

or

at the middle of your loop

write

if (i == 1000){
  int a = 1;
}

and break over int a = 1;

The second method looks more like garbage, but I find it easier and faster to do

OTHER TIPS

Yes, you can in the debugger. It's called a "conditional breakpoint." Basically, right click on the red breakpoint and go to the "condition" option.

A quick google turned this and this up:

P.S. The last one is VS 2005, but it's the same in 2008.

In visual studio you can set a conditional breakpoint - set a breakpoint at the point where you want to break as normal and then right click on the brown circle in the left margin and select "conditional breakpoint..." or whatever. You then type in an expression that evaluates to true when you want to break (e.g. i == 1000, or MyString = "hello world")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top