删除不必要的相等运算符(IDE0100)

财产 价值
规则 ID IDE0100
标题 删除不必要的相等运算符
类别 样式
子类别 不必要的代码规则(表达式级首选项)
适用的语言 C# 和 Visual Basic

概述

此样式规则在将非常量布尔表达式与常量 truefalse进行比较时标记不必要的相等运算符。

选项

此规则没有关联的代码样式选项。

// Code with violations
if (x == true) { }
if (M() != false) { }

// Fixed code
if (x) { }
if (M()) { }
' Code with violations
If x = True Then
End If

If M() <> False Then
End If

' Fixed code
If x Then
End If

If M() Then
End If

禁止显示警告

如果只想取消单个冲突,请将预处理器指令添加到源文件以禁用,然后重新启用规则。

#pragma warning disable IDE0100
// The code that's violating the rule is on this line.
#pragma warning restore IDE0100

若要禁用文件、文件夹或项目的规则,请将其严重性设置为 配置文件中的 none

[*.{cs,vb}]
dotnet_diagnostic.IDE0100.severity = none

若要禁用所有代码样式规则,请将类别 Style 的严重性设置为 配置文件中的 none

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

有关详细信息,请参阅 如何取消代码分析警告

另请参阅