Search code examples
c#breakpoints

I sometimes add code to insert a breakpoint. Is there another way? If not, what's the best solution?


This is a silly thing I catch myself doing once in a while and I feel that it is a bad habit. It usually goes like this:

  1. I try to place a breakpoint but cannot because there is not a valid stopping point for the processor.
  2. So I insert a silly code to break on and then delete later. (unless it gets forgotten D:)

For example, let's say I want to pause inside an empty constructor like this one:

public ImAConstructor()
{
    //I want to break here but can't :(
}

So I do something like this instead:

public ImAConstructor()
{
    int testVar = 0; //TODO: Delete this code. Temporarily inserted to break on.
}

Which just feels ugly to type and probably upsets the programming gods.

I would like a way to do this that doesn't risk leaving pointless code that could confuse others.


Solution

  • If you are using VisualStudio to develop your application, you should be able to place a breakpoint on the opening { and the closing } bracket.