【发布时间】:2014-02-18 10:44:13
【问题描述】:
有什么区别
var list = new List<UserType>
{
new UserType(...),
new UserType(...),
};
和
var list = new List<UserType>()
{
new UserType(...),
new UserType(...),
};
?
我以前总是使用第二个,认为我只需要调用列表的无参数(或任何其他)构造函数...
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
ReSharper 之类的工具会通知您在使用初始化程序时可以删除
()。假设你没有参数。
标签: c# list initializer