Advertise with us

How to debug a C# program

Posted by  Htwe Htwe
 1941  View(s)
Rate this:
Hi All,

Please explain to me how to debug a C# program using visual studio with examples.

Thanks And Regards
  1. Re: How to debug a C# program

    Hi Htwe!

    For debugging you application follow the below steps

    Step 1: Breakpoints

    Breakpoint is used to notify debugger where and when to pause the execution of program. You can put a breakpoint in code by clicking on the side bar of code or by just pressing F9 at the front of the line. 

    Step 2: Step Over

    After debugger hits the breakpoint, you may need to execute the code line by line. "Step Over" [ F10 ] command is used to execute the code line by line. This will execute the currently highlighted line and then pause. If you select F10 while a method call statement is highlighted, the execution will stop after the next line of the calling statement.

    Step 3: Step Into

    This is similar to Step Over. The only difference is, if the current highlighted section is any methods call, the debugger will go inside the method. Shortcut key for Step Into is "F11". 

    Step 4: Step Out

    This is related when you are debugging inside a method. If you press the Shift - F11 within the current method, then the execution will complete the execution of the method and will pause at the next statement from where it called.