> ## 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.

# AL0038 - Use GetOrNull/GetOrDefault

> Replace TryGetValue ternary patterns with dictionary extensions

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

## Description

The pattern `dict.TryGetValue(key, out var v) ? v : null` is verbose. ANcpLua.Roslyn.Utilities provides cleaner dictionary access extensions.

## Bad Code

```csharp theme={null}
// Verbose TryGetValue patterns
var value = dict.TryGetValue(key, out var v) ? v : null;
var item = cache.TryGetValue(id, out var i) ? i : default;
```

## Good Code

```csharp theme={null}
using ANcpLua.Roslyn.Utilities;

// Clean extension methods
var value = dict.GetOrNull(key);
var item = cache.GetOrDefault(id);
```

## Properties

* **Category**: Usage
* **Severity**: Warning
* **Enabled by default**: True
* **Code fix available**: False

## Configuration

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

## Notes

* `GetOrNull()` - returns `null` for missing keys (reference types)
* `GetOrDefault()` - returns `default(T)` for missing keys
* Works with `Dictionary<K,V>`, `IDictionary<K,V>`, `IReadOnlyDictionary<K,V>`
