I'm trying to get the properties from my Toys array which is in the Animal object.
My current attempt which works fine til I'm trying to reach the fields of the Toy object from the Toys array:
- var anonTypeArr = Petowner.Pets.Select(
- x => new {
- x.Age,
- x.Name,
- x.Toys.Select(
- y => new
- {
- y.Name,
- y.Color
- }
- )
- }).ToArray();
- dataGridView1.DataSource = anonTypeArr;
My animal class:
- abstract class Animal
- {
- public string Name { get; set; }
- public virtual int Age { get; set; }
- public List Toys { get; set; } = new List(); // How can I get the fields from a toy object?
- }
My toy class
- abstract class Toy
- {
- public virtual string Name { get; set; }
- public virtual string Color { get; set; }
- public virtual string Size { get; set; }
- public int Quality { get; set; } = 10;
-
- }