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 | Element Operator | First
- LINQ | Set Operator | Union
- LINQ | Set Operator | Intersect
- LINQ | Quantifier Operator | Contains
- LINQ | Element Operator | Last
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Distinct
- LINQ | Quantifier Operator | Any
- LINQ | Partition Operator | Take
- LINQ | Generation Operator | DefaultIfEmpty
- LINQ | Grouping Operator | ToLooKUp
- LINQ | Grouping Operator | GroupBy
- LINQ | Element Operator | ElementAtOrDefault
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.