# C# 代码质量的 CodeQL 查询

浏览 CodeQL 用于分析 C# 编写的代码质量的查询。

Code Quality 使用以下 CodeQL 查询来分析 C# 代码并检测代码质量问题：

* 你的**默认分支**，结果显示在存储库的“常规发现”仪表板上
* 
              **拉取请求**，结果显示为由 `github-code-quality[bot]` 发表的评论

尽可能为结果提供 Copilot自动修复 建议。

<div class="ghd-tool rowheaders">

| 查询名称 | 类别 | Severity |
| --- | --- | --- |
| 
              [使用单个 Response.Write（） 阻止代码](https://codeql.github.com/codeql-query-help/csharp/cs-asp-response-write/) | 可维护性 | 建议 |
| 
              [调用过时的方法](https://codeql.github.com/codeql-query-help/csharp/cs-call-to-obsolete-method/) | 可维护性 | 警告 |
| 
              [类与超级类同名](https://codeql.github.com/codeql-query-help/csharp/cs-class-name-matches-base-class/) | 可维护性 | 建议 |
| 
              [类实现 ICloneable](https://codeql.github.com/codeql-query-help/csharp/cs-class-implements-icloneable/) | 可维护性 | 建议 |
| 
              [常量条件](https://codeql.github.com/codeql-query-help/csharp/cs-constant-condition/) | 可维护性 | 警告 |
| 
              [永远不会访问容器内容](https://codeql.github.com/codeql-query-help/csharp/cs-unused-collection/) | 可维护性 | 错误 |
| 
              [在超类中设置字段掩码](https://codeql.github.com/codeql-query-help/csharp/cs-field-masks-base-field/) | 可维护性 | 警告 |
| 
              [无用的条件](https://codeql.github.com/codeql-query-help/csharp/cs-useless-if-statement/) | 可维护性 | 警告 |
| 
              [本地范围变量隐藏成员](https://codeql.github.com/codeql-query-help/csharp/cs-local-shadows-member/) | 可维护性 | 建议 |
| 
              [错过了“只读”机会](https://codeql.github.com/codeql-query-help/csharp/cs-missed-readonly-modifier/) | 可维护性 | 建议 |
| 
              [错过了“使用”机会](https://codeql.github.com/codeql-query-help/csharp/cs-missed-using-statement/) | 可维护性 | 建议 |
| 
              [错过使用 All 的机会](https://codeql.github.com/codeql-query-help/csharp/cs-linq-missed-all/) | 可维护性 | 建议 |
| 
              [错过了使用 Cast 的机会](https://codeql.github.com/codeql-query-help/csharp/cs-linq-missed-cast/) | 可维护性 | 建议 |
| 
              [错过使用 OfType 的机会](https://codeql.github.com/codeql-query-help/csharp/cs-linq-missed-oftype/) | 可维护性 | 建议 |
| 
              [错过使用 Select 的机会](https://codeql.github.com/codeql-query-help/csharp/cs-linq-missed-select/) | 可维护性 | 建议 |
| 
              [错过了使用 Where 条件的机会](https://codeql.github.com/codeql-query-help/csharp/cs-linq-missed-where/) | 可维护性 | 建议 |
| 
              [错过使用三元运算符的机会](https://codeql.github.com/codeql-query-help/csharp/cs-missed-ternary-operator/) | 可维护性 | 建议 |
| 
              [嵌套的“if”语句可以组合](https://codeql.github.com/codeql-query-help/csharp/cs-nested-if-statements/) | 可维护性 | 建议 |
| 
              [冗余选择](https://codeql.github.com/codeql-query-help/csharp/cs-linq-useless-select/) | 可维护性 | 警告 |
| 
              [冗余 ToString（）调用](https://codeql.github.com/codeql-query-help/csharp/cs-useless-tostring-call/) | 可维护性 | 建议 |
| 
              [实例方法编写的静态字段](https://codeql.github.com/codeql-query-help/csharp/cs-static-field-written-by-instance/) | 可维护性 | 建议 |
| 
              [不必要的复杂布尔表达式](https://codeql.github.com/codeql-query-help/csharp/cs-simplifiable-boolean-expression/) | 可维护性 | 建议 |
| 
              [未使用的标签](https://codeql.github.com/codeql-query-help/csharp/cs-unused-label/) | 可维护性 | 警告 |
| 
              [对局部变量的无用赋值](https://codeql.github.com/codeql-query-help/csharp/cs-useless-assignment-to-local/) | 可维护性 | 警告 |
| 
              [对 GetHashCode() 的无用调用](https://codeql.github.com/codeql-query-help/csharp/cs-useless-gethashcode-call/) | 可维护性 | 建议 |
| 
              [在等待期间持有 lock](https://codeql.github.com/codeql-query-help/csharp/cs-locked-wait/) | Reliability | 警告 |
| 
              [调用“System.IO.Path.Combine”可能会无提示地删除其早期参数](https://codeql.github.com/codeql-query-help/csharp/cs-path-combine/) | Reliability | 建议 |
| 
              [调用 GC.Collect()](https://codeql.github.com/codeql-query-help/csharp/cs-call-to-gc/) | Reliability | 警告 |
| 
              [对值类型表达式调用 ReferenceEquals（...）](https://codeql.github.com/codeql-query-help/csharp/cs-reference-equality-on-valuetypes/) | Reliability | 错误 |
| 
              [对非托管代码的调用](https://codeql.github.com/codeql-query-help/csharp/cs-call-to-unmanaged-code/) | Reliability | 建议 |
| 
              [将“this”强制转换为类型参数](https://codeql.github.com/codeql-query-help/csharp/cs-cast-of-this-to-type-parameter/) | Reliability | 建议 |
| 
              [传递给 StringBuilder 构造函数的字符](https://codeql.github.com/codeql-query-help/csharp/cs-stringbuilder-initialized-with-character/) | Reliability | 错误 |
| 
              [相同值的比较](https://codeql.github.com/codeql-query-help/csharp/cs-comparison-of-identical-expressions/) | Reliability | 警告 |
| 
              [容器内容永远不会初始化](https://codeql.github.com/codeql-query-help/csharp/cs-empty-collection/) | Reliability | 错误 |
| 
              [容器大小与零相比](https://codeql.github.com/codeql-query-help/csharp/cs-test-for-negative-container-size/) | Reliability | 警告 |
| 
              [解引用的变量始终为 null](https://codeql.github.com/codeql-query-help/csharp/cs-dereferenced-value-is-always-null/) | Reliability | 错误 |
| 
              [取消引用的变量可能为 null](https://codeql.github.com/codeql-query-help/csharp/cs-dereferenced-value-may-be-null/) | Reliability | 警告 |
| 
              [“这个”的可疑向下转换](https://codeql.github.com/codeql-query-help/csharp/cs-downcast-of-this/) | Reliability | 警告 |
| 
              [“this”的可疑类型测试](https://codeql.github.com/codeql-query-help/csharp/cs-type-test-of-this/) | Reliability | 警告 |
| 
              [条件的空分支，或空循环体](https://codeql.github.com/codeql-query-help/csharp/cs-empty-block/) | Reliability | 警告 |
| 
              [空锁语句](https://codeql.github.com/codeql-query-help/csharp/cs-empty-lock-statement/) | Reliability | 警告 |
| 
              [浮点值的相等性检查](https://codeql.github.com/codeql-query-help/csharp/cs-equality-on-floats/) | Reliability | 警告 |
| 
              [集合中的相等性](https://codeql.github.com/codeql-query-help/csharp/cs-equals-on-arrays/) | Reliability | 建议 |
| 
              [与不可比类型相等](https://codeql.github.com/codeql-query-help/csharp/cs-equals-on-unrelated-types/) | Reliability | 错误 |
| 
              [公开内部表示形式](https://codeql.github.com/codeql-query-help/csharp/cs-expose-implementation/) | Reliability | 建议 |
| 
              [字段的无效同步](https://codeql.github.com/codeql-query-help/csharp/cs-unsafe-sync-on-field/) | Reliability | 错误 |
| 
              [泛型 catch 子句](https://codeql.github.com/codeql-query-help/csharp/cs-catch-of-all-exceptions/) | Reliability | 建议 |
| 
              [没有 GetHashCode 定义的哈希值](https://codeql.github.com/codeql-query-help/csharp/cs-gethashcode-is-not-defined/) | Reliability | 警告 |
| 
              [无法进行数组强制转换](https://codeql.github.com/codeql-query-help/csharp/cs-impossible-array-cast/) | Reliability | 错误 |
| 
              [锁序列不一致](https://codeql.github.com/codeql-query-help/csharp/cs-inconsistent-lock-sequence/) | Reliability | 错误 |
| 
              [ContainsKey 的使用效率低下](https://codeql.github.com/codeql-query-help/csharp/cs-inefficient-containskey/) | Reliability | 建议 |
| 
              [无效的字符串格式](https://codeql.github.com/codeql-query-help/csharp/cs-invalid-string-formatting/) | Reliability | 错误 |
| 
              [在 lock 语句中锁定“this”对象](https://codeql.github.com/codeql-query-help/csharp/cs-lock-this/) | Reliability | 警告 |
| 
              [未对本地 IDisposable 执行 Dispose 调用](https://codeql.github.com/codeql-query-help/csharp/cs-local-not-disposed/) | Reliability | 警告 |
| 
              [具有相同变量的嵌套循环](https://codeql.github.com/codeql-query-help/csharp/cs-nested-loops-with-same-variable/) | Reliability | 警告 |
| 
              [将 Null 作为参数传递给 Equals(object)](https://codeql.github.com/codeql-query-help/csharp/cs-null-argument-to-equals/) | Reliability | 警告 |
| 
              [与容器长度逐个比较](https://codeql.github.com/codeql-query-help/csharp/cs-index-out-of-bounds/) | Reliability | 错误 |
| 
              [错误处理不佳：捕获 NullReferenceException](https://codeql.github.com/codeql-query-help/csharp/cs-catch-nullreferenceexception/) | Reliability | 警告 |
| 
              [错误处理不佳：空捕获块](https://codeql.github.com/codeql-query-help/csharp/cs-empty-catch-block/) | Reliability | 建议 |
| 
              [精度可能丢失](https://codeql.github.com/codeql-query-help/csharp/cs-loss-of-precision/) | Reliability | 错误 |
| 
              [非短路逻辑的潜在危险使用](https://codeql.github.com/codeql-query-help/csharp/cs-non-short-circuit/) | Reliability | 错误 |
| 
              [设置属性时不使用属性值](https://codeql.github.com/codeql-query-help/csharp/cs-unused-property-value/) | Reliability | 警告 |
| 
              [对 Equals（object） 的递归调用](https://codeql.github.com/codeql-query-help/csharp/cs-recursive-equals-call/) | Reliability | 错误 |
| 
              [重新抛出异常变量](https://codeql.github.com/codeql-query-help/csharp/cs-rethrown-exception-variable/) | Reliability | 警告 |
| 
              [自我分配](https://codeql.github.com/codeql-query-help/csharp/cs-self-assignment/) | Reliability | 错误 |
| 
              [循环中的字符串串联](https://codeql.github.com/codeql-query-help/csharp/cs-string-concatenation-in-loop/) | Reliability | 建议 |
| 
              [循环创建 StringBuilder](https://codeql.github.com/codeql-query-help/csharp/cs-stringbuilder-creation-in-loop/) | Reliability | 建议 |
| 
              [Equals 方法中未经检查的强制转换](https://codeql.github.com/codeql-query-help/csharp/cs-unchecked-cast-in-equals/) | Reliability | 警告 |
| 
              [非托管代码](https://codeql.github.com/codeql-query-help/csharp/cs-unmanaged-code/) | Reliability | 建议 |
| 
              [使用默认 ToString（）](https://codeql.github.com/codeql-query-help/csharp/cs-call-to-object-tostring/) | Reliability | 警告 |

</div>