База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / C#

System.Collections.Generic.IEnumerator: практическа справка

System.Collections.Generic.IEnumerator: практическа справка: IEnumerator<T> е курсор със състояние, придвижван от MoveNext, а Current предоставя елемента на валидната позиция.

Версия: .NET API; verified on .NET 10.0.14

Синтаксис

System.Collections.Generic.IEnumerator /* select a documented member or constructor */

IEnumerator е курсор със състояние, придвижван от MoveNext, а Current предоставя елемента на валидната позиция.

Обикновено го използвайте чрез foreach; при пряка употреба винаги осигурявайте извикване на Dispose.

Current няма полезен договор преди първия успешен MoveNext или след като MoveNext върне false.

Reset може да не се поддържа, а промяна на основната колекция обикновено обезсилва enumerator.

Пълната програма действително използва System.Collections.Generic.IEnumerator; точният очакван stdout е 8.

Примери

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);

Резултат

8

Пълната програма действително използва `System.Collections.Generic.IEnumerator`; точният очакван stdout е `8`.

Източници