Aracılığıyla paylaş


Debug.Assert Method (Boolean, String, String)

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

Checks for a condition and displays two specified messages if the condition is false.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
<ConditionalAttribute("DEBUG")> _
Public Shared Sub Assert ( _
    condition As Boolean, _
    message As String, _
    detailMessage As String _
)
[SecuritySafeCriticalAttribute]
[ConditionalAttribute("DEBUG")]
public static void Assert(
    bool condition,
    string message,
    string detailMessage
)

Parameters

  • condition
    Type: System.Boolean
    The conditional expression to evaluate. If the condition is true, the specified messages are not displayed.
  • detailMessage
    Type: System.String
    A detailed message to display.

Remarks

Typically, the Assert method is used to identify logic errors during program development. Assert evaluates a specified condition. If the result is false, it sends diagnostics to the debugger.

The Assert(Boolean, String, String) overload displays two messages that you specify.

The default behavior displays an Assert dialog box when the application runs in user-interface mode, and outputs the messages to the debugger when in debug mode.

NoteNote:

The Assert method behaves differently in Silverlight-based applications than it does in desktop applications. When an Assert occurs in Windows, a dialog box is displayed with two options, OK and Cancel. Cancel causes the debugger to break at the Assert statement, OK causes it to continue. On the Apple Macintosh OS X, the dialog box only provides the option to continue. In either case, if a debugger is not currently attached, you may attach one before you close the dialog box. On the Apple Macintosh OS X, managed debugging can be done only through remote debugging on a Windows computer by using a Visual Studio plug-in.

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.