logo search
CSharp_Prog_Guide

Отладка

На любом этапе работы в редакторе кода можно задать точку останова на строке кода, нажав клавишу F9. При нажатии клавиши F5 для запуска приложения в отладчике Visual Studio, приложение остановится на этой строке и можно будет увидеть значение заданной переменной или просмотреть, как и когда прерывается цикл выполнения, пройти по каждой строке кода при помощи клавиши F10, или задать дополнительные точки останова.

--------

You can also set conditional breakpoints, which will only stop execution if a specified condition is met. Tracepoints are like breakpoints except that they do not stop execution, but just write the value of a specified variable to the output window.

When execution is stopped on a breakpoint, you can hover over any variable in scope to view information about that variable. The following illustration shows a data tip in the debugger:

You can step through your code one line at a time by pressing F10 after the debugger has stopped on a breakpoint. You can even fix certain kinds of errors in your code, and continue debugging without having to stop and recompile your application.

The Visual Studio debugger is a powerful tool and it is worthwhile to take the time to read the documentation in order to understand different concepts such as Edit and Continue, Viewing Data in the Debugger, Visualizers, and Just-In-Time Debugging.

Можно также задать условные точки останова, при которых выполнение будет прерываться только при выполнении заданного условия. Точки трассировки аналогичны точкам останова за тем исключением, что они не прерывают выполнение, а лишь записывают значение заданной переменной в окне вывода.

При прерывании выполнения на точке останова можно навести курсор на любую переменную в границах представления для просмотра сведений об этой переменной. На рисунке ниже показана подсказка в отладчике:

Для перехода по строкам кода по порядку можно воспользоваться клавишей F10 после остановки отладчика на точке останова. Можно даже исправить определенные типы ошибок в коде и продолжить отладку без необходимости остановки и повторной компиляции приложения.

Отладчик Visual Studio является мощным средством и рекомендуется уделить время прочтению документации, чтобы понять различные концепции, такие как Режим "Изменить и продолжить", Просмотр данных в отладчике, Визуализаторы и JIT-отладка.

Modeling and Analyzing Code

It is not uncommon for software developers to work with source code whose basic architecture is unfamiliar either because it was written by someone else, or because it was written so long ago that its original creators no longer recall completely how it works. Another common scenario is the need to understand the contents of a library that is only available in binary format. Visual C# provides the following tools to help you model, analyze, and understand types and type relationships in source code as well as in binary assemblies:

In addition to the tools listed above, Visual Studio Team System includes the Code Analysis for Managed Code tool that inspects your code for a wide variety of potential problems.

Class Designer

Class Designer is a graphical tool for visually modeling the relationship between types in a software application or component; you can also use it to design new types and refactor or delete existing types. The following illustration shows a simple class design: