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"}
}
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.
var persons = new []
{
new { ID = 1, Name = "Name1" },
new { ID = 2, Name = "Name2" }
}