System.Linq.Enumerable

The Enumerable class provides a set of static methods for querying objects that implement IEnumerable<T>. These methods enable functional programming techniques such as filtering, projection, aggregation, and more.

Namespace

System.Linq

Assembly

System.Core.dll

Methods

Where
IEnumerable<TSource> Where<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate)

Filters a sequence of values based on a predicate.

var numbers = new[] {1,2,3,4,5};
var even = numbers.Where(n => n % 2 == 0);
foreach(var n in even) Console.WriteLine(n); // 2 4

View full documentation

Select
IEnumerable<TResult> Select<TSource,TResult>(IEnumerable<TSource> source, Func<TSource, TResult> selector)

Projects each element of a sequence into a new form.

var words = new[] {"apple","banana","cherry"};
var lengths = words.Select(w => w.Length);

View full documentation

FirstOrDefault
TSource FirstOrDefault<TSource>(IEnumerable<TSource> source)

Returns the first element of a sequence, or a default value if the sequence contains no elements.

var empty = new int[0];
var first = empty.FirstOrDefault(); // 0 (default int)

View full documentation

Any
bool Any<TSource>(IEnumerable<TSource> source)

Determines whether a sequence contains any elements.

var list = new List<int>();
bool hasElements = list.Any(); // false

View full documentation

… (other methods omitted for brevity) …

See Also