Skip to main content
Source: AL0003DontDivideByConstantZeroAnalyzer.cs

Description

Integers and Decimal should never be divided by the constant 0 as this causes a DivideByZeroException at runtime.

Bad Code

int result = value / 0;

Good Code

int result = divisor != 0 ? value / divisor : 0;

Properties

  • Category: Reliability
  • Severity: Error
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0003.severity = warning