ImmutableArrayExtensions.SingleOrDefault Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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. |
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
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);
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
Type Parameters
- T
The type of element contained by the collection.
Parameters
- immutableArray
- ImmutableArray<T>
The array.
Returns
The element in the array, or the default value if the array is empty.
Exceptions
source
contains more than one element.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9 |
.NET Framework | 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided) |
.NET Standard | 2.0 (package-provided) |
UWP | 10.0 |
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
- Source:
- ImmutableArrayExtensions.cs
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);
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
Type Parameters
- T
The type of element contained by the collection.
Parameters
- immutableArray
- ImmutableArray<T>
The array to get the element from.
Returns
The element if it satisfies the specified condition; otherwise the default element.
Exceptions
More than one element satisfies the condition in predicate
.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9 |
.NET Framework | 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided) |
.NET Standard | 2.0 (package-provided) |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: