Element Operations

Element Operations

 

Element operations return a single, specific element from a sequence.

The standard query operator methods that perform element operations are listed in the following section.

Method Name

Description

C# Query Expression Syntax

Visual Basic Query Expression Syntax

More Information

ElementAt

Returns the element at a specified index in a collection.

Not applicable.

Not applicable.

Enumerable.ElementAt<TSource>

Queryable.ElementAt<TSource>

ElementAtOrDefault

Returns the element at a specified index in a collection or a default value if the index is out of range.

Not applicable.

Not applicable.

Enumerable.ElementAtOrDefault<TSource>

Queryable.ElementAtOrDefault<TSource>

First

Returns the first element of a collection, or the first element that satisfies a condition.

Not applicable.

Not applicable.

Enumerable.First<TSource>

Queryable.First<TSource>

FirstOrDefault

Returns the first element of a collection, or the first element that satisfies a condition. Returns a default value if no such element exists.

Not applicable.

Not applicable.

Enumerable.FirstOrDefault<TSource>

Queryable.FirstOrDefault<TSource>

Queryable.FirstOrDefault<TSource>(IQueryable<TSource>)

Last

Returns the last element of a collection, or the last element that satisfies a condition.

Not applicable.

Not applicable.

Enumerable.Last<TSource>

Queryable.Last<TSource>

LastOrDefault

Returns the last element of a collection, or the last element that satisfies a condition. Returns a default value if no such element exists.

Not applicable.

Not applicable.

Enumerable.LastOrDefault<TSource>

Queryable.LastOrDefault<TSource>

Single

Returns the only element of a collection, or the only element that satisfies a condition.

Not applicable.

Not applicable.

Enumerable.Single<TSource>

Queryable.Single<TSource>

SingleOrDefault

Returns the only element of a collection, or the only element that satisfies a condition. Returns a default value if no such element exists or the collection does not contain exactly one element.

Not applicable.

Not applicable.

Enumerable.SingleOrDefault<TSource>

Queryable.SingleOrDefault<TSource>

Show:
© 2016 Microsoft