. NET (C #): use code to add breakpoints and display custom information in the Visual Studio output window.

Source: Internet
Author: User

Zookeeper

The two tasks must be completed by the Debugger class. The System. Diagnostics. Debugger type allows us to interact with the Debugger. It is easy to understand that there are not many members of the Debugger type. (MSDN)

First, you must use the IsAttached attribute to determine whether the current process has attached a debugger. If so, use the IsLogging method to determine whether the current append debugger supports logging. If both are true, you can use the Log method to record messages safely. The Log Content is displayed in the Visual Studio output window.

The Debugger. Break method forces the Debugger to perform breakpoint processing when running the current code.

Code:

// + Using System. diagnostics; // determine whether to append the Debugger. // determine whether the Debugger supports the Message Log if (Debugger. isAttached & Debugger. isLogging () {// record Debugger. log (1, "joke", "This code must be well debugged! "); // Add the breakpoint Debugger. Break ();}

Debug and run the above Code (you can directly press F5). Visual Studio will debug the breakpoint on the Debugger. Break () line of code, and the output window will have our custom information, such:



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.