Visual Studio – How to set condition on breakpoint


Lets finish this year with one of the handy and time saving option available in visual studio i.e.set condition on breakpoint.

it is very handy and crucial time saver when your code contain very long iteration or loop and you want breakpoint would be break on certain condition only.

Lets understand this with actual example.suppose I would like to debug following code.

            for (int i = 0; i < 10; i++)
                Console.WriteLine("i is " + i);

Now, i want only debugger hit only when i is equal to 4.

Lets find out how we can achieve it.

  1. right click on breakpoint on which you would like to set condition and click on Condition option .


2. set the appropriate condition. for understanding purpose, i have set condition i==4.

Screen Shot 2

3. now start the debugging. now you will noticed that breakpoint will hit only one time I.e. when i is equal to 4. not every time or not throughout iteration (for loop).

Screen Shot 5

Hope this will help you.


Reply and suggestions are warmly appreciated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s