开发者

Can I define an array or a list from anonymous class?

Can I def开发者_高级运维ine an array or a list from anonymous class?

like this:

persons = new ... [] 
{
 new { ID = 1, Name = "Name1"},
 new { ID = 2, Name = "Name2"}
}


Yes, you'll just need to type the persons variable implicitly and remove the type specifier from the array creation statement.

var persons = new []
{
    new { ID = 1, Name = "Name1" },
    new { ID = 2, Name = "Name2" }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜