TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chris Anderson
NA
93
9.4k
How to nest lists in list?
Jan 13 2021 11:06 AM
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
{
// Create a new object of type Petowner
Petowner petowner =
new
Petowner();
public
void
CreateDummyAnimals()
{
//Create dummy animals at start
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"
},
}
},
}
});
}
Reply
Answers (
2
)
Cannot implicity convert int to int[]
Get property in inerrited class