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?
As a user I would suggest the following: make a hotkey to exit the loop in debugging mode, for example ctrl-shift-F11.
The "Set Next Statement" (CTRL+SHIFT+F10) shortcut will work at the end of a function... but you need to use the mouse though as well. On VS 2019 there are those green arrows in front of lines, hold CTRL key and you can set next statement directly there, skipping anything in between.
Go to your code
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
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With