JetBrains Rider 2025.2 Help

代码检查:转换为 'using' 声明

如果 示意图 语句位于代码块的末尾,此检查建议将其转换为 示意图 声明的更简洁语法。

资源将在包含块的末尾被释放,因此这是一个减少代码嵌套而不降低可读性的机会。

void ReadFile(string path) { using (StreamReader reader = File.OpenText(path)) { while (reader.ReadLine() is { }) { // do something } } }
void ReadFile(string path) { using StreamReader reader = File.OpenText(path); while (reader.ReadLine() is { }) { // do something } }
最后修改日期: 2025年 9月 26日