简体   繁体   English

我可以从匿名类中定义数组或列表吗?

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

Can I define 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. 是的,您只需要隐式输入persons变量并从数组创建语句中删除类型说明符。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM