System.Linq Namespace
Overview
The System.Linq namespace provides classes and interfaces that support queries
that use Language-Integrated Query (LINQ). It includes standard query operators that
operate on generic collections (IEnumerable<T>) and on data sources
that implement IQueryable<T>.
using System;
using System.Linq;
using System.Collections.Generic;
var numbers = new List<int> { 1, 2, 3, 4, 5 };
var even = numbers.Where(n => n % 2 == 0);
Console.WriteLine(string.Join(", ", even));
Classes
| Name | Summary |
|---|---|
| Enumerable | Provides a set of static methods for querying objects that implement IEnumerable<T>. |
| Queryable | Provides a set of static methods for querying data structures that implement IQueryable<T>. |
Interfaces
| Name | Summary |
|---|---|
| IOrderedEnumerable<TElement> | Represents a sorted sequence. |
Enumerations
None
Extension Methods
The most commonly used LINQ operators are listed below. Click a method name for detailed documentation.
| Method | Signature | Description |
|---|---|---|
| Where | IEnumerable<TSource> Where(this IEnumerable<TSource> source, Func<TSource, bool> predicate) |
Filters a sequence based on a predicate. |
| Select | IEnumerable<TResult> Select(this IEnumerable<TSource> source, Func<TSource, TResult> selector) |
Projects each element of a sequence into a new form. |
| OrderBy | IOrderedEnumerable<TSource> OrderBy(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) |
Sorts the elements of a sequence in ascending order. |
| GroupBy | IEnumerable<IGrouping<TKey, TSource>> GroupBy(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) |
Groups the elements of a sequence according to a specified key selector function. |