Filtering operators are those operators which are used to filter the data according to the user requirement from the given data source or from the given sequence. For example, in an employee record, we want to get the data of the employees whose age in 21. So, we filter the record, according to their age. In LINQ, you can filter using the following operators:
Where operator filters the value according to the predicate function. Or in words, we can say it returns the values from the sequence based on the given condition or criteria. Where clause is not a mandatory clause in the query.
Where Clause in Query Syntax: The where clause is used to filter the query according to the given condition. You can provide a condition to where clause using lambda expression or by using Func delegate type. Where clause supports query syntax in both C# and VB.Net languages. Query Syntax of Where clause is as shown in the below example.
Employee Name: Anjita Employee Name: Soniya Employee Name: Rohit
Where Clause in Method Syntax: In Method syntax, Where clause works as a method. It present in both the Queryable and Enumerable class. It supports method syntax in both C# and VB.NET languages. The use of the Where method is shown in the below example.
Employee Name: Supriya Employee Name: Anil Employee Name: Anju
Multiple Where Clause: In LINQ, you are allowed to use multiple where clause or Where method in the single query. As shown in the below example:
- LINQ | Filtering Operator | OfType
- LINQ | Set Operator | Except
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Intersect
- LINQ | Set Operator | Union
- LINQ | Element Operator | First
- LINQ | Partition Operator | Take
- LINQ | Element Operator | Last
- LINQ | Quantifier Operator | Contains
- LINQ | Quantifier Operator | Any
- LINQ | Set Operator | Distinct
- LINQ | Equality Operator | SequenceEqual
- LINQ | Sorting Operator | ThenByDescending
- LINQ | Projection Operator | SelectMany
- LINQ | Projection Operator | Select
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.