开发者

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

开发者 https://www.devze.com 2023-01-19 18:42 出处:网络
Can I def开发者_高级运维ine an array or a list from anonymous class? like this: persons = new ... []

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

精彩评论

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