Common debugging tips for sharing in Visual Studio 2015

Source: Internet
Author: User

. NET Technology Exchange Group: 337901356 Welcome to join!

Why learn to debug?

Debugging (Debug) is a programmer must learn something, learn to debug can greatly improve the development efficiency, troubleshooting time, many people do not like debugging, but I think this is a very undesirable choice, when debugging can let us see the program's execution sequence, steps and processes, etc. debugging allows us to monitor the situation of variables in the code so that we can quickly find the source of the error. Visible debugging is critical.

To learn how to debug, then you have to understand the different debugging techniques in the IDE, and I'll talk about the techniques I've used in debugging a lot.

Introduction to Debugging Techniques

1. Monitoring window (ctrl+d,ctrl+w shortcut key on)

In the process of debugging the program, we can dynamically see the values of each variable and the return result of each function's call through this window.

In the Watch window, we can also manually change the value of a variable, which is sometimes useful, especially sometimes when the program executes to the specified statement, found that a value is wrong, but we want to test the code with a correct value,

You can now change the value of the variable directly from the Watch window without restarting debugging.

Quick Watch: Select a variable with the latter expression and open it by pressing the shortcut key ctrl+d,ctrl+q.

Note: This window can only be opened in debugging situations.

2. Call Stack (CTRL+D,CTRL+C)

Through this window, we can see the function of the first level of the call process, we can know that the method is from the above which one of the steps to initiate the call. 、

You can open the call Stack window by tapping the call stack, window, Debug.

Such as:

Note: This window can be turned on only in debugging situations.

3, drag the debugging cursor skills.

Visual Studio in the case of debugging can drag the left side of the yellow arrow to drag up and down, then what is the role of this, sometimes we may want to practical F11 with a method inside the call process of the view, the result of a careless found hand mistakenly pressed the F10, At this time the code executes to the next sentence of the method call, then we can click on the left side of the yellow arrow, and hold down the left mouse button, to the previous drag, this time, you can also execute the method called the code, if dragged down, then you can skip the execution of some statement code.

4. Edit and Continue

By enabling editing and continuing, you can change part of the code directly while debugging the code, and then immediately execute the latest code without restarting the debugger.

But the downside of this approach in a Web application is that after you've set up a startup edit and continue, if you end debugging at this point, the Web site or Web application will automatically exit from Iisexpress, and then refresh the page, which will show that you can't connect to the site. If you want to continue browsing other pages, you will have to restart the site at this point.

However, in Visual Studio 2015, the default is to open the Edit and Continue feature, and the Edit and Continue check box has been removed.

5. Set Breakpoint (F9 shortcut key on)

The advantage of breakpoints is that if a method or program contains a lot of code, then we can set it to a place where we want the program to stop, and F5 can quickly execute to the next breakpoint.

When we start debugging, if the program has a large number of breakpoints, and we just want to debug a certain part of the code, then perhaps some people will be a breakpoint to cancel or disable, feel tired enough,

In fact, you can delete all breakpoints by clicking Debug, Disable all breakpoints, or debug, if you decide you don't need to reset those breakpoints, you can delete all breakpoints, otherwise it is recommended to disable all breakpoints, and then turn those breakpoints on when you need to enable breakpoint debugging.

There is a more special breakpoint setting: Conditional breakpoint

A conditional breakpoint is a statement that can be hit only when an expression is set and the value of the expression is true or changed.

Look at an example.

6, the use of F5 keys

In Visual Studio, F5 can be used to start debugging, can also quickly execute the program from one breakpoint to the next breakpoint, often some novice will be the execution of a sentence to debug, if the program code is not a few words OK, if the program code, or encounter a large cycle of the turn, When will the hand be pressed to execute to the specified code that you want to debug?

7, F10 process

F10 represents the step-by-step execution of code, what is the process of execution, the popular point is that when the execution of a method of the statement, debugging will not go inside the method, but one way to complete the execution of the method.

8, F11 statement

F11 is the execution of the code on a per-statement basis, then if the statement that invokes the method is encountered, then through F11 can enter the execution process inside the method.

9. Switch Completion mode

Sometimes you find that after you have manually played some English, the smart box will never automatically check what we want to select, but instead become the following:

Then, you can enter the shortcut key: ctrl+alt+ SPACEBAR to switch to the selected mode.

In general, the main debugging skills are these, explained here are the daily development of a more commonly used in debugging, hope to help the novice.

Common debugging tips for sharing in Visual Studio 2015

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.