Skip to main content

Description

Combines a variable declaration and an immediate null-check into a single pattern match.

Bad Code

var x = GetValue();
if (x != null)
{
    Use(x);
}

Good Code

if (GetValue() is { } x)
{
    Use(x);
}

Properties

  • Category: Style
  • Severity: Info
  • Enabled by default: True
  • Code fix available: True

Configuration

dotnet_diagnostic.AL0016.severity = warning