Contract.Assume Method
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.
Instructs code analysis tools to assume that a condition is true
, even if it cannot be statically proven to always be true
.
Assume(Boolean) |
Instructs code analysis tools to assume that the specified condition is |
Assume(Boolean, String) |
Instructs code analysis tools to assume that a condition is |
- Source:
- Contracts.cs
- Source:
- Contracts.cs
- Source:
- Contracts.cs
Instructs code analysis tools to assume that the specified condition is true
, even if it cannot be statically proven to always be true
.
public:
static void Assume(bool condition);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition);
[<System.Diagnostics.Conditional("DEBUG")>]
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member Assume : bool -> unit
Public Shared Sub Assume (condition As Boolean)
Parameters
- condition
- Boolean
The conditional expression to assume true
.
- Attributes
Remarks
At run time, using this method is equivalent to using the Assert(Boolean) method.
Applies to
.NET 10 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
- Source:
- Contracts.cs
- Source:
- Contracts.cs
- Source:
- Contracts.cs
Instructs code analysis tools to assume that a condition is true
, even if it cannot be statically proven to always be true
, and displays a message if the assumption fails.
public:
static void Assume(bool condition, System::String ^ userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition, string userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition, string? userMessage);
[<System.Diagnostics.Conditional("DEBUG")>]
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member Assume : bool * string -> unit
Public Shared Sub Assume (condition As Boolean, userMessage As String)
Parameters
- condition
- Boolean
The conditional expression to assume true
.
- userMessage
- String
The message to post if the assumption fails.
- Attributes
Remarks
If userMessage
is not a constant string literal, the contract may not be understood by tools.
At run time, using this method is equivalent to using the Assert(Boolean, String) method.
Applies to
.NET 10 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: