> ## Documentation Index
> Fetch the complete documentation index at: https://ancplua.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AL0048 - Use non-negative guard helper

> Use Guard.NotNegative() instead of verbose if (x < 0) throw patterns

Source: [Al0048UseGuardNotNegativeAnalyzer.cs](https://github.com/ANcpLua/ANcpLua.Analyzers/blob/main/src/ANcpLua.Analyzers/Analyzers/Al0048UseGuardNotNegativeAnalyzer.cs)

## Description

Use `Guard.NotNegative()` instead of verbose negative-check and throw patterns.

## Bad Code

```csharp theme={null}
public void SetCount(int count)
{
    if (count < 0)
        throw new ArgumentOutOfRangeException(nameof(count));
}
```

## Good Code

```csharp theme={null}
public void SetCount(int count)
{
    Guard.NotNegative(count);
}
```

## Properties

* **Category**: Roslyn Utilities
* **Severity**: Warning
* **Enabled by default**: True
* **Code fix available**: True

## Configuration

```editorconfig theme={null}
dotnet_diagnostic.AL0048.severity = warning
```
