Enumerable.Single<'TSource> Method (IEnumerable<'TSource>, Func<'TSource, Boolean>)
Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.
Assembly: System.Core (in System.Core.dll)
static member Single<'TSource> : source:IEnumerable<'TSource> * predicate:Func<'TSource, bool> -> 'TSource
An IEnumerable<'T> to return a single element from.
The single element of the input sequence that satisfies a condition.
The type of the elements of source.
The following code example demonstrates how to useto select the only element of an array that satisfies a condition.
The following code example demonstrates thatthrows an exception when the sequence does not contain exactly one element that satisfies the condition.
Available since 8
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1