Time for action – learn how to go about creating a Where() clause
Suppose there is a
Student class and we want to find only those students who have enrolled for the C# course:
- We want to find all students whose
C#. Write the Lambda expression for that:
s => s.Course.Equals("C#")
- Pass this Lambda expression to the
Where()clause (sometimes, LSQO are referred to as clauses) as follows:
Students.Where(s => s.Course.Equals("C#") );
- Receive the result of this operation in an implicit variable, as shown next:
var cSharpStudents = Students.Where(s => s.Course.Equals("C#") );
What just happened?
We have a
Student objects and we wanted to find all the students that have opted for C#. Assuming
Course is a public property of the
Student object, ...