ImmutableArrayExtensions.SingleOrDefault 方法

定义

重载

SingleOrDefault<T>(ImmutableArray<T>)

返回数组中的唯一元素;如果序列为空,则返回默认值;如果序列包含多个元素,此方法将引发异常。Returns the only element of the array, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

SingleOrDefault<T>(ImmutableArray<T>, Func<T,Boolean>)

返回序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

SingleOrDefault<T>(ImmutableArray<T>)

返回数组中的唯一元素;如果序列为空,则返回默认值;如果序列包含多个元素,此方法将引发异常。Returns the only element of the array, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T SingleOrDefault(System::Collections::Immutable::ImmutableArray<T> immutableArray);
public static T SingleOrDefault<T> (this System.Collections.Immutable.ImmutableArray<T> immutableArray);
static member SingleOrDefault : System.Collections.Immutable.ImmutableArray<'T> -> 'T
<Extension()>
Public Function SingleOrDefault(Of T) (immutableArray As ImmutableArray(Of T)) As T

类型参数

T

集合包含的元素的类型。The type of element contained by the collection.

参数

immutableArray
ImmutableArray<T>

数组。The array.

返回

T

数组中的元素;如果数组为空,则为默认值。The element in the array, or the default value if the array is empty.

异常

source 包含多个元素。source contains more than one element.

SingleOrDefault<T>(ImmutableArray<T>, Func<T,Boolean>)

返回序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T SingleOrDefault(System::Collections::Immutable::ImmutableArray<T> immutableArray, Func<T, bool> ^ predicate);
public static T SingleOrDefault<T> (this System.Collections.Immutable.ImmutableArray<T> immutableArray, Func<T,bool> predicate);
static member SingleOrDefault : System.Collections.Immutable.ImmutableArray<'T> * Func<'T, bool> -> 'T
<Extension()>
Public Function SingleOrDefault(Of T) (immutableArray As ImmutableArray(Of T), predicate As Func(Of T, Boolean)) As T

类型参数

T

集合包含的元素的类型。The type of element contained by the collection.

参数

immutableArray
ImmutableArray<T>

要从中获取元素的数组。The array to get the element from.

predicate
Func<T,Boolean>

元素必须满足的条件。The condition the element must satisfy.

返回

T

如果该元素满足指定的条件,则返回该元素;否则返回默认元素。The element if it satisfies the specified condition; otherwise the default element.

异常

多个元素满足 predicate 中的条件。More than one element satisfies the condition in predicate.

适用于