Conditional breakpoint in Visual Studio

Captain Comic picture Captain Comic · Feb 19, 2010 · Viewed 39.1k times · Source

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

Danny G picture Danny G · Feb 19, 2010

if (MyStringVariable == "LKOH") Debugger.Break();

you'll need System.Diagnostics namespace

http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx