Поделиться через


Debug Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides a set of methods and properties that help debug your code. This class cannot be inherited.

Inheritance Hierarchy

System.Object
  System.Diagnostics.Debug

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

Syntax

'Declaration
Public NotInheritable Class Debug
public static class Debug

The Debug type exposes the following members.

Methods

  Name Description
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Assert(Boolean) Checks for a condition and outputs the call stack if the condition is false.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Assert(Boolean, String) Checks for a condition and displays a specified message if the condition is false.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Assert(Boolean, String, String) Checks for a condition and displays two specified messages if the condition is false.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Assert(Boolean, String, String, array<Object[]) Checks for a condition and outputs the message and the call stack if the condition is false.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteLine(Object) Writes the value of a specified object's ToString method to the debugger by using the OutputDebugString function.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteLine(String) Writes a specified message followed by a line terminator to the debugger by using the OutputDebugString function.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteLine(String, array<Object[]) Writes a formatted string followed by a line terminator to the debugger by using the OutputDebugString function.

Top

Remarks

If you use methods in the Debug class to display debugging information and check your logic with assertions, you can make your code more robust without affecting the performance and code size of your shipping product.

This class provides methods for displaying an Assert dialog box, and for emitting an assertion that will always fail. This class provides write methods in the following variations: WriteLine(Object), WriteLine(String), and WriteLine(String, array<Object[]).

NoteNote:

The debugging methods in the Debug class behave differently in Silverlight-based applications than they do in desktop applications. There is no Listeners collection to specify the destination for debug output. In Windows, the .NET Framework for Silverlight sends debugging information to the OutputDebugString function and to the debugger, if one is attached. The Visual Studio debugger displays the information in the Output window. If a debugger is not attached, the output from OutputDebugString can be viewed by using a debug viewer. The Apple Macintosh OS X does not have an OutputDebugString function. Therefore, managed debugging can be done only through remote debugging on a Windows computer by using a Visual Studio plug-in.

To define the "DEBUG" conditional compilation symbol in C#, add the /d:DEBUG option to the compiler command line when you compile your code or add #define DEBUG to the top of your file. In Visual Basic, add the /d:DEBUG=True option to the compiler command line or add #Const DEBUG=True to the file.

In Visual Studio projects, by default, the "DEBUG" conditional compilation symbol is defined for debug builds, and the "TRACE" symbol is defined for both debug and release builds. For information on how to disable this behavior, see the Visual Studio documentation.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

This type is thread safe.

See Also

Reference