Quantifier Operators

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Quantifier Operators:

The quantifier operators evaluate elements of the sequence on some condition and return a boolean value to indicate that some or all elements satisfy the condition.

Operator Description
All Checks if all the elements in a sequence satisfies the specified condition
Any Checks if any of the elements in a sequence satisfies the specified condition
Contain Checks if the sequence contains a specific element

All:

The All operator evalutes each elements in the given collection on a specified condition and returns True if all the elements satisfy a condition.

Example: All operator C#


IList<Student> studentList = new List<Student>() { 
        new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
        new Student() { StudentID = 2, StudentName = "Steve",  Age = 15 } ,
        new Student() { StudentID = 3, StudentName = "Bill",  Age = 25 } ,
        new Student() { StudentID = 4, StudentName = "Ram" , Age = 20 } ,
        new Student() { StudentID = 5, StudentName = "Ron" , Age = 19 } 
    };

// checks whether all the students are teenagers    
bool areAllStudentsTeenAger = studentList.All(s => s.Age > 12 && s.Age < 20);

Console.WriteLine(areAllStudentsTeenAger);

Example: All operator VB.Net


Dim areAllStudentsTeenAger = studentList.All(Function(s) s.Age > 12 And s.Age < 20)
        

Output:

false
 
Note :Quantifier operators are Not Supported with C# query syntax.

Learn about quanifier operator - Contains in the next section.