I am debugging a C# program in Visual Studio. Consider the following snippet.
var List<string> cars = {"honda","bmw","ferrari","ford","jaguar"};
foreach (string car in cars){
purchaseCar(car);
}
I wish to debug the purchaseCar() function when it is called for car="ford". However, while debugging in Visual Studio, I will have to step over(F10) the purchaseCar() function for previous three cars until I can finally step into(F11) it. This would be really tedious if there were a larger number of previous elements.
I wish to know if there is anyway I can directly jump to the ith iteration of a loop while debugging in Visual Studio.
Rather than thinking of it as "jumping to a particular iteration" I would suggest using a conditional break point.
Add the break-point in Visual Studio, e.g. on the purchaseCar(car)
line, then right click on it and select "Conditions...". You can then set a condition, which in this case would be car == "ford"
. Let the debugger run, and it will only break when the condition is true.
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