Edit and Contiue Features
When you debug a program, you often encounter situations like this: In Debugging a large section of code, encountered a small error, such as the parameters of the assignment error, at this time, often hope that these small errors can be corrected immediately after, can continue to debug tracking, without ending the entire debugging process to modify. In Visual Studio 2003, we have to stop the current debugging, modify the wrong place, and recompile, which is inconvenient. In Visual Studio 2005, provides a new feature called "Edit and Continue", meaning that when you are debugging, encountered a small error need to modify immediately, you can edit, and then continue to debug, do not need to end the entire debugging process, when you modify, It is convenient for the debugger to compile automatically in the background and execute the newly modified code. Here is an example to illustrate.
Open Visual Studio 2005, use C # to build an WinForm form application, add a label label to a form, a text box, a button, as shown in the following figure, the function we want to implement is that when you enter some information in the text box, the click button pops up a message box, The information that you just entered is displayed.
If we write the code as follows, there is a small error, the TextBox1.Text content as a part of the string, so the user input information is not displayed.
private void button1_Click(object sender, EventArgs e)
{
//Show welcome message
MessageBox.Show("Welcome textbox1.Text to Edit and Continue.");
}
Now, if we encounter this error while debugging, we can use the Edit and continue feature to correct it.
First, press F7 to switch to Code view, set breakpoints in the MessageBox.Show line, then press F5 to run the program, when the text box input string, because set the interrupt, the cursor stops on the MessageBox.Show line, at this time, we can modify the code, modified to:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Welcome " + textbox1.Text +" to Edit and Continue.");
}
After the modification, continue to press F5 run, this time, will show the correct results, the following figure, and do not need to use the previous "Stop debugging" function to stop debugging and then modify the program.