All rules
IDE0241Unnecessary code rules (expression-level preferences)
Nullable directive is unnecessary
Nullable directive is unnecessary
Microsoft docsDescription
This rule flags places where a #nullable directive is unnecessary. The directive is unnecessary where there are no reference types that would be impacted by the nullable context scope change. For example:
#nullable enablein a project where nullable context is already enabled.#nullable disablein a project where nullable context is already disabled.#nullable disablefor an enumeration.#nullable disableor#nullable restoreat the end of a file that includes#nullable enablein a project where nullable context is disabled.
Example
// Code with violations (in a project with <Nullable>enable</Nullable>).
#nullable disable
enum Place
{
First,
Second
}
// Fixed code.
enum Place
{
First,
Second
}Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0