CKTIS / C#
System.Collections.Generic.IEnumerator: referencia práctica
System.Collections.Generic.IEnumerator: referencia práctica: IEnumerator<T> es un cursor con estado que avanza mediante MoveNext y cuyo Current expone el elemento en una posición válida.
Versión: .NET API; verified on .NET 10.0.14
Sintaxis
System.Collections.Generic.IEnumerator /* select a documented member or constructor */IEnumerator es un cursor con estado que avanza mediante MoveNext y cuyo Current expone el elemento en una posición válida.
Consúmelo normalmente con foreach; si lo usas directamente, garantiza siempre la llamada a Dispose.
Current no tiene un contrato útil antes del primer MoveNext correcto ni después de que MoveNext devuelva false.
Reset puede no estar soportado y modificar la colección subyacente suele invalidar el enumerador.
El programa completo usa realmente System.Collections.Generic.IEnumerator; su stdout esperado exacto es 8.
Ejemplos
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
El programa completo usa realmente `System.Collections.Generic.IEnumerator`; su stdout esperado exacto es `8`.