Visual C# throws an exception when a runtime error occurs. If this exception is not handled, the program is finished.
In Visual Studio, breakpoints are saved with the project. You don’t have to reset all your break points each time you open the project.
Action That Can be Taken at a Break Point
Action | Keystroke | Description |
Continue Code Execute | F5 | Continues execution at the current break statement |
Step Into | F11 | Executes the statement at the break point and then stops at the next statement. If the current statement is a function call, F11 enters the function and stops at the first statement in function. |
Step Over | F10 | Executes the statement at the break point and then stops at the next statement. If the current statement is a function call, the function is run in its entirety; execution stops at the statement following the function call. |
Step Out | Shift + F11 | Runs all the statements in the current procedure and halts execution at the statement following the one that called the current procedure. |
Stop Debugging | Shift + F5 | Stops debugging the project and returns to design mode. |
Only Visual Studio 2008 supports on-the-fly code editing – you can modify code while debugging it.
Output window – Visual C# uses the Output window to display various status messages and build errors. The most useful feature of the Output window, is the capability to send data to it from a running application.
To print data to the Output window, use the WriteLine() method of the Debug object, like this:
System.Diagnostics.Debug.WriteLine(“Results = “ + lngResults);
Whatever you place withing the parentheses of the WriteLine() method is what is printed to the Output window. Note that you can print literal text and numbers, variables, or expressions. WriteLine() is most useful in cases where you want to know the value of a variable, but you don’t want to halt code execution using a break point. For instance, suppose you have a number of statements that manipulate a variable. You can sprinkle WriteLine() statements into the code to print the variable’s content at strategic points.
Just remember that the Output Window isn’t available to a compiled component; calls to the Debug object are ignored by the compiler when creating distributable components.