All rules
IDE0370Unnecessary code rules (suppression preferences)

Remove unnecessary suppression

Remove unnecessary suppression

Microsoft docs

Description

This rule identifies unnecessary nullable warning suppressions using the null-forgiving operator (!). The null-forgiving operator tells the compiler that the value is not null, which suppresses warnings for nullable reference types. However, when the compiler can already determine that a value is not null, the null-forgiving operator is unnecessary and can be removed.

Example

// Code with violations.
#nullable enable

void ProcessValue()
{
    List<string> names = new()!;
}

// Fixed code.
#nullable enable

void ProcessValue()
{
    List<string> names = new(); // No suppression needed.
}
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0