Debugging is very useful technique to test your code that does it works the way you want. In debugging you put break points in your code to check the flow of the program execution and values of the local and global variables at that point of time.
In Visual Studio it is very easy to debug code. Just put the cursor on the line where you want to set a break point, hit F9 key, or click on the gray area in the left most column of the line. To unset break point just hit F9 key again or click on the break point it will remove the break point from that line of code.
After setting the break point Run your code by press F5 key, execution will be stopped on the break point. Now you have many options here to resume the execution. You can move line by line by pressing F10( Step Over) key, or if a line contains a method call then you can press F11 key (Step Into) to go into the function and do the same thing here or You can press F5 key to continue the execution of the program until the next break point is reached or to the end of the program.
During debugging you can check the values of variables by hovering the mouse over them or right click on the variable and choose “Quick Watch” or “Add to Watch” option from the context menu.
You should debug each and every line of the code where you feel that a problem can occur.