Common LINQ Operations
Filter collections and sort the output using LINQ queries.
We'll cover the following
Basic syntax
All LINQ queries have nearly identical structures:
var result = from item in collection
select item;
- The
collection
is a collection object (like an array or list). - The
item
refers to an individual element of that collection. - The
select
statement is used to choose what should be returned as a result.
This is the basic syntax. It can be extended from here through filtering, sorting, projection, and so on. We’ll explore these operations individually.
Filter
To select items that match some criteria, we use the where
clause. After the where
keyword, we provide a boolean expression that determines how the filtering occurs:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy