แก้ไข

แชร์ผ่าน


AsyncEnumerable.FirstOrDefaultAsync Method

Definition

Overloads

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, TSource, CancellationToken)

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, TSource, CancellationToken)

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

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, TSource, CancellationToken)

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, CancellationToken)

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, CancellationToken)

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

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, CancellationToken)

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, TSource, CancellationToken)

Source:
FirstAsync.cs

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

public static System.Threading.Tasks.ValueTask<TSource> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,bool> predicate, TSource defaultValue, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, bool> * 'Source * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, Boolean), defaultValue As TSource, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> to return an element from.

predicate
Func<TSource,Boolean>

A function to test each element for a condition.

defaultValue
TSource

The default value to return if the sequence is empty.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

defaultValue if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Exceptions

predicate is null.

Applies to

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, TSource, CancellationToken)

Source:
FirstAsync.cs

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

public static System.Threading.Tasks.ValueTask<TSource> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, TSource defaultValue, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * 'Source * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), defaultValue As TSource, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

The IAsyncEnumerable<T> to return the first element of.

defaultValue
TSource

The default value to return if the sequence is empty.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

defaultValue if source is empty; otherwise, the first element in source.

Exceptions

source is null.

Applies to

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, TSource, CancellationToken)

Source:
FirstAsync.cs

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

public static System.Threading.Tasks.ValueTask<TSource> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<bool>> predicate, TSource defaultValue, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<bool>> * 'Source * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, CancellationToken, ValueTask(Of Boolean)), defaultValue As TSource, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> to return an element from.

predicate
Func<TSource,CancellationToken,ValueTask<Boolean>>

A function to test each element for a condition.

defaultValue
TSource

The default value to return if the sequence is empty.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

defaultValue if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Exceptions

predicate is null.

Applies to

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, CancellationToken)

Source:
FirstAsync.cs

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

public static System.Threading.Tasks.ValueTask<TSource?> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,bool> predicate, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, bool> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, Boolean), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

Parameters

source
IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> to return an element from.

predicate
Func<TSource,Boolean>

A function to test each element for a condition.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

The default value of TSource if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Exceptions

predicate is null.

Applies to

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, CancellationToken)

Source:
FirstAsync.cs

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

public static System.Threading.Tasks.ValueTask<TSource?> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

The IAsyncEnumerable<T> to return the first element of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

The default value of TSource if source is empty; otherwise, the first element in source.

Exceptions

source is null.

Applies to

FirstOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, CancellationToken)

Source:
FirstAsync.cs

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

public static System.Threading.Tasks.ValueTask<TSource?> FirstOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<bool>> predicate, System.Threading.CancellationToken cancellationToken = default);
static member FirstOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function FirstOrDefaultAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, CancellationToken, ValueTask(Of Boolean)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)

Type Parameters

TSource

Parameters

source
IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> to return an element from.

predicate
Func<TSource,CancellationToken,ValueTask<Boolean>>

A function to test each element for a condition.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<TSource>

The default value of TSource if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Exceptions

predicate is null.

Applies to