CKTIS / C#
System.Collections.Generic.IEnumerator: referência prática
System.Collections.Generic.IEnumerator: referência prática: IEnumerator<T> é um cursor com estado avançado por MoveNext, e Current expõe o elemento na posição válida.
Versão: .NET API; verified on .NET 10.0.14
Sintaxe
System.Collections.Generic.IEnumerator /* select a documented member or constructor */IEnumerator é um cursor com estado avançado por MoveNext, e Current expõe o elemento na posição válida.
Consome-o normalmente através de foreach; ao usá-lo diretamente, garante sempre a chamada a Dispose.
Current não tem contrato útil antes do primeiro MoveNext bem-sucedido nem depois de MoveNext devolver false.
Reset pode não ser suportado e alterar a coleção subjacente normalmente invalida o enumerador.
O programa completo usa realmente System.Collections.Generic.IEnumerator; o stdout exato esperado é 8.
Exemplos
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;
using IEnumerator<int> iterator = new List<int> { 8 }.GetEnumerator();
Console.WriteLine(iterator.MoveNext() ? iterator.Current : -1);
Resultado
8
O programa completo usa realmente `System.Collections.Generic.IEnumerator`; o stdout exato esperado é `8`.