Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Assert Method (Boolean, String)
Collapse the table of content
Expand the table of content

Contract.Assert Method (Boolean, String)

Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer and displays the specified message.

Namespace:  System.Diagnostics.Contracts
Assemblies:   mscorlib (in mscorlib.dll)
  System.Diagnostics.Contracts (in System.Diagnostics.Contracts.dll)

'Declaration
<ConditionalAttribute("DEBUG")> _
<ConditionalAttribute("CONTRACTS_FULL")> _
Public Shared Sub Assert ( _
	condition As Boolean, _
	userMessage As String _
)

Parameters

condition
Type: System.Boolean

The conditional expression to test.

userMessage
Type: System.String

A message to display if the condition is not met.

The default escalation policy is to notify the attached debugger about a contract failure or to display an Assert dialog box if a debugger is not attached. Optionally, the analyzer can be instructed to throw an exception. The userMessage parameter is passed to the debugger output. If userMessage is not a constant string literal, tools may not be able to read it.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft