代码检查:集合初始值设定项中冗余的大括号
此检查会在集合初始值设定项元素仅包含单个非赋值值时报告其大括号。 在这种情况下,多余的大括号没有必要,还会降低初始值设定项的可读性。
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日