Conditional C# breakpoint?

此生再无相见时 提交于 2019-11-27 17:58:47

问题


I'm debugging a foreach loop which will iterate well over 1000 times - so I only want a breakpoint within the loop to break for a particular item.

So...

foreach(Employee employee in employees)
{
//DO SOMETHING
//BREAK HERE WHEN employee.Id == '2342'
//DO SOMETHING ELSE
}

Do I have to write an If statement and some dummy code within it and break it that way? That the only way?


回答1:


Just adding to the previous answers. Use Conditional Breakpoints.

You can specify the condition like below




回答2:


if (employee.Id == '2342') Debugger.Break();

Alternatively, you can set a conditional breakpoint in VS, but from my experience, that is incredibly slow.




回答3:


If you're using anything other than the express editions of VS right click on the breakpoint and click Set Condition.

Personally I'd use this approach as I'd consider it bad practice to modify your code to debug it.

Otherwise you're forced to do it your way.




回答4:


Use a VS debugger with conditional breakpoint, via UI.

The easiest and fastest way imo.

The Ultimate Visual Studio Tips and Tricks Blog




回答5:


You can use conditional breakpoints in Visual Studio.

Right click on the breakpoint and choose conditional and then put in your clause.



来源:https://stackoverflow.com/questions/11290485/conditional-c-sharp-breakpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!