Contract.Assert Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
In debug builds, performs a run-time test for a specified condition.
Overloads
Assert(Boolean) |
Checks for a condition; if the condition is |
Assert(Boolean, String) |
Checks for a condition; if the condition is |
Assert(Boolean)
- Source:
- Contracts.cs
- Source:
- Contracts.cs
- Source:
- Contracts.cs
Checks for a condition; if the condition is false
, follows the escalation policy set for the analyzer.
public:
static void Assert(bool condition);
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
[System.Diagnostics.Conditional("DEBUG")]
public static void Assert (bool condition);
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
[<System.Diagnostics.Conditional("DEBUG")>]
static member Assert : bool -> unit
Public Shared Sub Assert (condition As Boolean)
Parameters
- condition
- Boolean
The conditional expression to test.
- Attributes
Remarks
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.
Applies to
Assert(Boolean, String)
- Source:
- Contracts.cs
- Source:
- Contracts.cs
- Source:
- Contracts.cs
Checks for a condition; if the condition is false
, follows the escalation policy set by the analyzer and displays the specified message.
public:
static void Assert(bool condition, System::String ^ userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assert (bool condition, string userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assert (bool condition, string? userMessage);
[<System.Diagnostics.Conditional("DEBUG")>]
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member Assert : bool * string -> unit
Public Shared Sub Assert (condition As Boolean, userMessage As String)
Parameters
- condition
- Boolean
The conditional expression to test.
- userMessage
- String
A message to display if the condition is not met.
- Attributes
Remarks
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.