# Ensure

`Ensure` static class with its methods provides functionality for determining if variable's value meets specified conditions and throw exception if it's not.

## NotNull

Throws `ArgumentNullException` when value of specified variable is null:

```csharp
object myValue = null;
Ensure.NotNull(myValue, nameof(myValue)); // --> throws ArgumentNullException
myValue = "123456";
Ensure.NotNull(myValue, nameof(myValue)); // --> does nothing
```

## NotEmpty

Throws ArgumentNullException when value of specified string variable is null or empty or consists only of white-space characters:

```csharp
string? myValue = null;
Ensure.NotNull(myValue, nameof(myValue)); // --> throws ArgumentNullException
myValue = "        ";
Ensure.NotNull(myValue, nameof(myValue)); // --> throws ArgumentNullException
myValue = "abcdef";
Ensure.NotNull(myValue, nameof(myValue)); // --> does nothing
```

## Other methods

Other methods to check variables are listed below:

* InRange
* GreaterThan
* LessThan

Each of them got three different versions for `string`, `DateTime` and `IComparable` values.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.structr.dev/utilities/abstractions/ensure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
