Dictionary<TKey,TValue>.Enumerator 구조체

정의

Dictionary<TKey,TValue>의 요소를 열거합니다.

public: value class Dictionary<TKey, TValue>::Enumerator : System::Collections::Generic::IEnumerator<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::IDictionaryEnumerator
public struct Dictionary<TKey,TValue>.Enumerator : System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.IDictionaryEnumerator
[System.Serializable]
public struct Dictionary<TKey,TValue>.Enumerator : System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.IDictionaryEnumerator
type Dictionary<'Key, 'Value>.Enumerator = struct
    interface IEnumerator<KeyValuePair<'Key, 'Value>>
    interface IEnumerator
    interface IDisposable
    interface IDictionaryEnumerator
[<System.Serializable>]
type Dictionary<'Key, 'Value>.Enumerator = struct
    interface IEnumerator<KeyValuePair<'Key, 'Value>>
    interface IDisposable
    interface IDictionaryEnumerator
    interface IEnumerator
[<System.Serializable>]
type Dictionary<'Key, 'Value>.Enumerator = struct
    interface IEnumerator<KeyValuePair<'Key, 'Value>>
    interface IDisposable
    interface IEnumerator
    interface IDictionaryEnumerator
type Dictionary<'Key, 'Value>.Enumerator = struct
    interface IEnumerator<KeyValuePair<'Key, 'Value>>
    interface IDictionaryEnumerator
    interface IEnumerator
    interface IDisposable
[<System.Serializable>]
type Dictionary<'Key, 'Value>.Enumerator = struct
    interface IEnumerator<KeyValuePair<'Key, 'Value>>
    interface IDictionaryEnumerator
    interface IDisposable
    interface IEnumerator
Public Structure Dictionary(Of TKey, TValue).Enumerator
Implements IDictionaryEnumerator, IEnumerator(Of KeyValuePair(Of TKey, TValue))

형식 매개 변수

TKey
TValue
상속
Dictionary<TKey,TValue>.Enumerator
특성
구현

설명

C# 언어for each(C++, For Each Visual Basic의 경우)의 문은 foreach 열거자의 복잡성을 숨깁니다. 그러므로 열거자를 직접 조작하는 대신 foreach를 사용하는 것이 좋습니다.

열거자를 사용하여 컬렉션의 데이터를 읽을 수는 있지만 내부 컬렉션을 수정할 수는 없습니다.

처음에 열거자는 컬렉션의 첫 번째 요소 앞에 배치됩니다. 이 위치에서 Current는 정의되지 않습니다. 값을 Current읽기 전에 를 호출 MoveNext 하여 열거자를 컬렉션의 첫 번째 요소로 진행해야 합니다.

CurrentMoveNext가 호출될 때까지 동일한 개체를 반환합니다. MoveNextCurrent를 다음 요소로 설정합니다.

경우 MoveNext 열거자를 컬렉션의 끝 컬렉션의 마지막 요소 뒤에 배치 되는 전달 하 고 MoveNext 반환 false합니다. 열거자가 있는 경우이 위치에 대 한 후속 호출은 MoveNext 반환할 수도 false합니다. 반환 falseCurrent 된 에 대한 MoveNext 마지막 호출이 정의되지 않은 경우 Current를 컬렉션의 첫 번째 요소로 다시 설정할 수 없으므로 대신 새 열거자 인스턴스를 만들어야 합니다.

컬렉션이 변경되지 않고 그대로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 요소 추가 또는 용량 변경과 같이 컬렉션이 변경되면 열거자가 취소할 수 없게 무효화되고 에 대한 다음 호출 MoveNext 또는 IEnumerator.Reset throw가 InvalidOperationException발생합니다.

.NET Core 3.0 이상만 해당: 열거자를 무효화하지 않는 유일한 변경 메서드는 및 Clear입니다Remove.

열거자는 컬렉션에 배타적으로 액세스하지 못하므로 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 열거 동안 스레드 보안을 보장하려면 전체 열거 동안 컬렉션을 잠그면 됩니다. 여러 스레드에서 컬렉션에 액세스하여 읽고 쓸 수 있도록 허용하려면 사용자 지정 동기화를 구현해야 합니다.

에서 System.Collections.Generic 컬렉션의 기본 구현은 동기화되지 않습니다.

속성

Current

열거자의 현재 위치에 있는 요소를 가져옵니다.

메서드

Dispose()

Dictionary<TKey,TValue>.Enumerator에서 사용하는 모든 리소스를 해제합니다.

MoveNext()

열거자를 Dictionary<TKey,TValue>의 다음 요소로 이동합니다.

명시적 인터페이스 구현

IDictionaryEnumerator.Entry

열거자의 현재 위치에 있는 요소를 가져옵니다.

IDictionaryEnumerator.Key

열거자의 현재 위치에 있는 요소의 키를 가져옵니다.

IDictionaryEnumerator.Value

열거자의 현재 위치에 있는 요소의 값을 가져옵니다.

IEnumerator.Current

열거자의 현재 위치에 있는 요소를 가져옵니다.

IEnumerator.Reset()

컬렉션의 첫 번째 요소 앞의 초기 위치에 열거자를 설정합니다.

적용 대상

추가 정보