CKTIS / C#
System.Collections.Generic.IAsyncEnumerable: praktická reference
System.Collections.Generic.IAsyncEnumerable: praktická reference: IAsyncEnumerable<T> představuje proud, jehož následné operace MoveNextAsync mohou na každý prvek asynchronně čekat.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Collections.Generic.IAsyncEnumerable /* select a documented member or constructor */IAsyncEnumerable představuje proud, jehož následné operace MoveNextAsync mohou na každý prvek asynchronně čekat.
Použijte jej pro postupně přicházející data, aby spotřebitel zpracovával prvky bez uložení celého výsledku.
Předávejte zrušení a uvolněte asynchronní enumerátor pomocí await foreach nebo await using.
Zdroj může být jednorázový, nekonečný nebo vyvolat výjimku až při dosažení pozdějšího prvku.
Úplný program skutečně používá System.Collections.Generic.IAsyncEnumerable; přesně očekávaný stdout je 7.
Příklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
await foreach (var value in Values()) Console.WriteLine(value);
static async IAsyncEnumerable<int> Values() { yield return 7; await Task.CompletedTask; }
Výsledek
7
Úplný program skutečně používá `System.Collections.Generic.IAsyncEnumerable`; přesně očekávaný stdout je `7`.