Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Debug Class

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

System.Object
  System.Diagnostics.Debug

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

public static class Debug

The Debug type exposes the following members.

  NameDescription
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Assert(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 360Assert(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 360Assert(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 360Assert(Boolean, String, String, 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 360WriteLine(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 360WriteLine(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 360WriteLine(String, Object[])Writes a formatted string followed by a line terminator to the debugger by using the OutputDebugString function.
Top

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, 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.

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

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

This type is thread safe.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft