I'm having problems when creating new list within another list. I'm trying to put the Murid list into the Toys list. The OOP and lists are quite tricky so any help is much appreciated!
The current code looks like following:
- abstract class Animal
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public List Toys { get; set; } = new List();
- }
- abstract class Toy
- {
- public int Quality { get; set; } = 10;
- public List Murids { get; set; } = new List();
- }
- abstract class Murid : Toy
- {
- public string Size { get; set; }
- }
- class Mouse : Murid
- {
- public string Something { get; set; }
- }
And this is how I try to create an instance of it:
- class Application
- {
-
- Petowner petowner = new Petowner();
-
- public void CreateDummyAnimals()
- {
-
-
- Petowner.Pets.Add(new Cat
- {
- Name = "Kisse",
- Age = 3,
- Toys =
- new List {
- new Bone {Quality = 5},
- new Ball { Quality = 7 },
- Murids =
- new List{
- new Mouse{Something = "Hello"},
- }
- },
-
- }
- });
- }