代码检查:集合初始化器中的多余大括号
此检查会在集合初始化器元素仅包含单个非赋值值时报告其外的大括号。 在此情况下,多余的大括号没有必要,会让初始化器更难阅读。
using System.Collections;
class C
{
object Create()
{
return new ArrayList { 1, { 2 } };
}
}
using System.Collections;
class C
{
object Create()
{
return new ArrayList { 1, 2 };
}
}
此检查不会报告必须使用大括号的元素,如多参数 Add(...) 调用。
2026年 5月 8日