SortedDictionary<TKey,TValue>.KeyCollection.Enumerator 結構

定義

public: value class SortedDictionary<TKey, TValue>::KeyCollection::Enumerator : System::Collections::Generic::IEnumerator<TKey>
public struct SortedDictionary<TKey,TValue>.KeyCollection.Enumerator : System.Collections.Generic.IEnumerator<TKey>
type SortedDictionary<'Key, 'Value>.KeyCollection.Enumerator = struct
    interface IEnumerator<'Key>
    interface IEnumerator
    interface IDisposable
type SortedDictionary<'Key, 'Value>.KeyCollection.Enumerator = struct
    interface IEnumerator<'Key>
    interface IDisposable
    interface IEnumerator
Public Structure SortedDictionary(Of TKey, TValue).KeyCollection.Enumerator
Implements IEnumerator(Of TKey)

類型參數

TKey
TValue
繼承
SortedDictionary<TKey,TValue>.KeyCollection.Enumerator
實作

備註

foreachC++ 中 C# 語言 (for each 的語句, For Each 在 Visual Basic 中) 會隱藏列舉值的複雜度。 因此,建議您使用 foreach,而不要直接使用列舉值。

列舉程式可以用來讀取集合中的資料,但是無法用來修改基礎集合。

一開始,列舉程式位在集合中的第一個項目之前。 在這個位置上,Current 並未定義。 您必須先呼叫 MoveNext 方法,將列舉值前移至集合的第一個專案,才能讀取 的值 Current

屬性 Current 會傳回相同的物件,直到 MoveNext 呼叫為止。 MoveNext 會將 Current 設定為下一個項目。

如果 MoveNext 傳遞集合結尾,列舉值會放在集合的最後一個專案後面,並 MoveNextfalse 回 。 當列舉值位於這個位置時,後續呼叫 MoveNext 也會傳回 false 。 如果最後一 MoveNext 次呼叫傳 false 回 , Current 則為未定義。 您不能再次將 Current 設定為集合的第一個項目;您必須建立新的列舉值執行個體。

只要集合維持不變,列舉值就仍維持有效。 如果對集合進行變更,例如新增、修改或刪除專案,列舉值就會無法復原,而下一次呼叫 MoveNextIEnumerator.Reset 會擲回 InvalidOperationException

列舉程式沒有集合的獨佔存取權,因此,列舉集合內容本質上並不是安全的執行緒程序。 若要確保列舉期間的執行緒安全性,您可以在整個列舉期間鎖定集合。 若要讓多重執行緒能夠存取集合以便進行讀取和寫入,您必須實作自己的同步處理。

System.Collections.Generic 命名空間中集合的預設實作未同步處理。

屬性

Current

取得位於目前列舉值位置的項目。

方法

Dispose()

釋放 SortedDictionary<TKey,TValue>.KeyCollection.Enumerator 所使用的所有資源。

MoveNext()

將列舉值前移至 SortedDictionary<TKey,TValue>.KeyCollection 的下一個項目。

明確介面實作

IEnumerator.Current

取得位於目前列舉值位置的項目。

IEnumerator.Reset()

設定列舉值至它的初始位置,這是在集合中第一個項目之前。

適用於

另請參閱