Back to: LINQ Tutorial For Beginners and Professionals
LINQ Quantifiers Operators in C#
In this article, I am going to discuss the LINQ Quantifiers Operators in C# with Examples. Please read our previous article where we discussed the LINQ Aggregate Method in C# with Examples. As part of this article, we are going to discuss the following pointers in detail.
What are the LINQ Quantifier Operators in C#?
We need to use the LINQ Quantifier Operators on a data source when we want to check if some or all of the elements of that data source satisfy a given condition or not. That means, here we have a data source and we also have a condition. Then we need to check whether all or some of the elements of that data source satisfied that given condition or not.
All Quantifier Methods are going to return a Boolean value. That means if all or some of the elements in the data source satisfy the given condition then it is going to return true else it is going to return false. The point that you need to remember is that the condition that we specify may be for some or all of the elements of the data source. If this is not clear at the moment, then don’t worry we will understand this with many different examples.
When to use LINQ Quantifier Operators in C#?
We need to use the LINQ Quantifier Operations on the below scenarios.
- When we want to check whether all the employees are present on a specific day or not.
- In a specific class of students, we need to check if any of the students have marks of more than 90%.
- When we need to check if any of the employees having the name James is present or not.
What Methods are Available in Quantifier Operations Category in C#?
The following three methods belong to the LINQ Quantifier Operations Category.
- All: This specifies whether all the elements of a data source satisfy a given condition or not. If all the elements satisfied the given condition, then it will return true else it will return false.
- Any: This specifies whether at least one of the elements of a data source satisfies the condition or not. If at least one element satisfied the given condition, then it will return true else it will return false.
- Contains: This method is used to check whether the data source contains a specified element or not. If the specific elements are present in the collection, then it will return true else it will return false.
Note: All of the above three methods return Boolean true or false depending on whether all or some of the elements in a data source satisfy the given condition.
In the next article, I am going to discuss the LINQ All Quantifier Operator with Examples. Here, in this article, I just try to explain what are and when to use LINQ Quantifier Operations in C#. I hope you enjoy this article.