I have a list of students with their subject of interests (separated by comma).
List<Students> students = new List<Students>();
students.Add(new Students() { Name = "Krishna", GroupID= 0, Interests = "Physics,Maths" });
students.Add(new Students() { Name = "Ganesh", GroupID= 0, Interests = "History,Physics" });
students.Add(new Students() { Name = "Jayesh", GroupID= 0, Interests = "Tech,Humanity" });
students.Add(new Students() { Name = "Aditya", GroupID= 0, Interests = "Science"});
students.Add(new Students() { Name = "Ramesh", GroupID= 0, Interests = "Programming,Science"});
I want to use the
Linq to edit the
GroupID of students in the same list based on their common interests.
Expected Output:
GroupID: 1
Students: Krishna, Ganesh
(Reason: Common interest in Physics)
GroupID: 2
Students: Aditya, Ramesh
(Reason: Common interest in Science)
Any help is greatly appreciated.
Thank you so much!
What I have tried:
Unfortunately, I'm not sure how to do this as I'm new to programming.