How can I modify the following code:
var people = new[] {
new { name = "John", surname = "Smith" },
new { name = "John", surname = "Doe" },
};
To not use the var keyword (so I can initialise the variable in an object initialiser) and still be able to access the elements like this?:
System.Console.WriteLine(people[0].surname); //John
System.Console.WriteLine(people[1].surname); //Doe
Define a model:
and then have a
collection of this model:or:
and then you can still: