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.1k
Get the properties from array in object to populate dataGridView
Feb 12 2021 6:02 PM
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(
// Psuedo code. How do I get fields from the Toys array here?
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;
}
Reply
Answers (
1
)
Open a UserControl when a column button is clicked (Windows App Form)
How to implement algorithm for trial version for 30 day by csharp ?