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

定義

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

類型參數

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

備註

foreach C++ 中的 C# (for each 語句,For Each在 Visual Basic 中) 會隱藏列舉值的複雜度。 因此,建議您使用 foreach,而不要直接使用列舉值。 此型別代表 IEnumerator<T> 介面。

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

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

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

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

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

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

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

屬性

Current

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

方法

Dispose()

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

MoveNext()

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

明確介面實作

IEnumerator.Current

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

IEnumerator.Reset()

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

適用於

另請參閱