
Using LINQ Where to Filter Data
LINQ
26 Articles
Table of Contents
What we gonna do?
This article explains how to use the Where method in LINQ to filter data in .NET.
Note: If you haven't already, read the article on Using LINQ OrderBy to Sort Data in collections.

Why we gonna do?
The Where method in LINQ allows filtering collections based on conditions. The resulting collection can be the same, smaller, or even empty. You can chain conditions using logical operators like &&, ||, and !.
How we gonna do?
Filtering by Single Property
Example of filtering a Product class by a single property.
Code Sample - LINQ Where Single Property
Filtering by Multiple Properties
Example of filtering a Product class by multiple properties using AND and OR operators.
Code Sample - LINQ Where Multiple Properties
Custom Extension Method
Create a custom extension method to filter a collection. This method returns an IEnumerable<T> and can be used on the query instead of the Where method.
Code Sample - LINQ Where Custom Extension Method
Summary
This article covered how to filter data in collections using LINQ. We explored filtering with single and multiple fields using AND and OR conditions, and created a custom extension method. These techniques can be used with any IEnumerable or IQueryable types.