Magic number (ARCH701)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.codequality.magic-number · Severity info · Category codequality
Numeric literals embedded directly in code reduce readability and hide intent. They should be replaced with named constants.
Incorrect
Section titled “Incorrect”public decimal CalculatePrice(decimal amount){ return amount * 1.18m;}Correct
Section titled “Correct”private const decimal VatRate = 1.18m;
public decimal CalculatePrice(decimal amount){ return amount * VatRate;}Move repeated or unclear numeric literals into a descriptively named const or static readonly field.