Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have list of data.

C#
class Student
{
public string class{get;set;}
public Enumerable<book> subjects{get;set;}
}

class Book{
public string language{get;set;}
public string science{get;set;}
}


I have Enumerable<students> list. i want to get class names where language name is English using C# or easiest way.

What I have tried:

C#
var lang= students.Select(i => new { i.class, i.subjects}).Select(j => j.subjects.Where(k => k.language.ToLower() == "english".ToLower()));
Posted
Updated 5-Oct-17 19:48pm
v2
Comments
[no name] 5-Oct-17 14:00pm    
You need to change the name of "class" to "classroom" variable declared in Student class. You cannot use class as its reserved keyword here.

1 solution

After correcting the problem mentioned in Vinod Jangle's comment, try this

//returns students having a specific language book
    var langStudents = students.Where(s => s.subjects.Any(x => s.Language.ToLower() == 
                       lang));
    return langStudents;
}
 
Share this answer
 
v2
Comments
Raj kumar.C 6-Oct-17 12:33pm    
i want to get class name only not subjects
Raj kumar.C 6-Oct-17 12:33pm    
anyway Thanks for your answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900