CKTIS / C#
System.Collections.Generic.IAsyncEnumerable: riferimento pratico
System.Collections.Generic.IAsyncEnumerable: riferimento pratico: IAsyncEnumerable<T> rappresenta un flusso le cui successive MoveNextAsync possono attendere ogni elemento in modo asincrono.
Versione: .NET API; verified on .NET 10.0.14
Sintassi
System.Collections.Generic.IAsyncEnumerable /* select a documented member or constructor */IAsyncEnumerable rappresenta un flusso le cui successive MoveNextAsync possono attendere ogni elemento in modo asincrono.
Usalo per dati che arrivano gradualmente, così il consumer elabora elementi senza memorizzare l’intero risultato.
Propaga la cancellazione e rilascia l’enumeratore asincrono tramite await foreach o await using.
Una sorgente può essere monouso, infinita o generare un’eccezione solo raggiungendo un elemento successivo.
Il programma completo usa realmente System.Collections.Generic.IAsyncEnumerable; lo stdout esatto atteso è 7.
Esempi
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; }
Risultato
7
Il programma completo usa realmente `System.Collections.Generic.IAsyncEnumerable`; lo stdout esatto atteso è `7`.