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
Istudent Rana
1.4k
360
85k
How to create a object from collection after grouping
Jan 11 2019 12:28 AM
I have list of Students which looks like below
List<StudentData> results= new List<StudentData>{
new Student{Id = 1, Name = "John", CourseName = "Math", CourseStatus ="Complete"},
new Student{Id = 1, Name = "John", CourseName = "Science", CourseStatus ="In Complete"},
new Student{Id = 1, Name = "John", CourseName = "English", CourseStatus ="Complete"},
new Student{Id = 2, Name = "Sarah", CourseName = "Math", CourseStatus ="Complete"},
new Student{Id = 2, Name = "Sarah", CourseName = "Computer", CourseStatus ="Complete"},
new Student{Id = 2, Name = "John Doe", CourseName = "Account", CourseStatus ="Complete"},
}
I want to create a Student with list of Course out from the above collection of data.
Student john = new Student();
john.Id = 1 , john.Name = "John", john.Courses = new List<Course>{
new Course{Name = "Math", CourseStatus ="Complete"},
new Course{Name = "Science", CourseStatus ="In Complete"},
new Course{Name = "English", CourseStatus ="Complete"},
}
How do i achieve this ?
What I have done so far is
var query= results.GroupBy(s=> s.Id);
foreach (var group in query)
{
foreach (var student in group )
{
}
}
Reply
Answers (
5
)
how to viewmodel with services in mvc
paytm .please help..i got below page while intigrate paytm