考虑一下
var source = new{ Id = "1", Name = "Name1"}
工作正常。但是,如果我想再增加一个属性怎么做......
失败
var source = new{ Id = "1", Name = "Name1"},new{ Id = "1", Name = "Name1"}
这是什么语法?
答案 0 :(得分:7)
在MSDN上查看Collection initializers和anonymous types:
var source = new [] { new { Id = "1", Name = "Name1"},
new { Id = "2", Name = "Name2"}};