SortedSet<T>.Enumerator 結構
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
列舉 SortedSet<T> 物件的項目。
public: value class SortedSet<T>::Enumerator : System::Collections::Generic::IEnumerator<T>
public: value class SortedSet<T>::Enumerator : System::Collections::Generic::IEnumerator<T>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public struct SortedSet<T>.Enumerator : System.Collections.Generic.IEnumerator<T>
public struct SortedSet<T>.Enumerator : System.Collections.Generic.IEnumerator<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public struct SortedSet<T>.Enumerator : System.Collections.Generic.IEnumerator<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type SortedSet<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IEnumerator
interface IDisposable
type SortedSet<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IEnumerator
interface IDisposable
interface IDeserializationCallback
interface ISerializable
[<System.Serializable>]
type SortedSet<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IDisposable
interface IEnumerator
interface ISerializable
interface IDeserializationCallback
Public Structure SortedSet(Of T).Enumerator
Implements IEnumerator(Of T)
Public Structure SortedSet(Of T).Enumerator
Implements IDeserializationCallback, IEnumerator(Of T), ISerializable
類型參數
- T
- 繼承
- 屬性
- 實作
備註
foreach C++ 中 C# 語言 (for each 的語句,For Each在 Visual Basic 中) 會隱藏列舉值的複雜度。 因此,建議您使用 foreach,而不要直接使用列舉值。
列舉程式可以用來讀取集合中的資料,但是無法用來修改基礎集合。
一開始,列舉程式位在集合中的第一個項目之前。 在這個位置, Current 屬性是未定義的。 因此,您必須先呼叫 MoveNext 方法,將列舉值前移至集合的第一個專案,然後再讀取 的值 Current。
Current 會傳回相同的物件直到呼叫 MoveNext。 MoveNext 會將 Current 設定為下一個項目。
如果 MoveNext 傳遞集合結尾,列舉值會放在集合的最後一個專案後面,並 MoveNext 傳 false回 。 當列舉值位於這個位置時,後續呼叫 MoveNext 也會傳回 false。 如果最後一 MoveNext 次呼叫傳 false回 , Current 則為未定義。 您無法再次設定 Current 為集合的第一個專案;您必須改為建立新的列舉值物件。
只要集合維持不變,列舉值就仍維持有效。 如果對集合進行變更,例如新增、修改或刪除專案,列舉值就會無法復原,而下一次呼叫 MoveNext 或 IEnumerator.Reset 會擲回 InvalidOperationException。
列舉值沒有集合的獨佔存取權;因此,透過集合列舉本質上不是安全線程程式。 若要確保列舉期間的執行緒安全性,您可以在整個列舉期間鎖定集合。 若要讓多重執行緒能夠存取集合以便進行讀取和寫入,您必須實作自己的同步處理。
System.Collections.Generic 命名空間中集合的預設實作未同步處理。
屬性
| Current |
取得位於目前列舉值位置的項目。 |
方法
| Dispose() |
釋放 SortedSet<T>.Enumerator 所使用的所有資源。 |
| MoveNext() |
讓列舉程式前進至 SortedSet<T> 集合中的下一個項目。 |
明確介面實作
| IDeserializationCallback.OnDeserialization(Object) |
實作 ISerializable 介面,並於還原序列化完成時引發還原序列化事件。 |
| IEnumerator.Current |
取得位於目前列舉值位置的項目。 |
| IEnumerator.Reset() |
設定列舉值至它的初始位置,這是在集合中第一個項目之前。 |
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
實作 ISerializable 介面,並傳回序列化 SortedSet<T> 執行個體所需的資料。 |