SortedSet<T>.Enumerator 结构

定义

枚举 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
[<System.Serializable>]
type SortedSet<'T>.Enumerator = struct
    interface IEnumerator<'T>
    interface IEnumerator
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
Public Structure SortedSet(Of T).Enumerator
Implements IEnumerator(Of T)
Public Structure SortedSet(Of T).Enumerator
Implements IDeserializationCallback, IEnumerator(Of T), ISerializable

类型参数

T
继承
SortedSet<T>.Enumerator
属性
实现

注解

foreach C# 语言的语句 (for each C++ 中的 For Each Visual Basic) 隐藏枚举器的复杂性。 因此,建议使用 foreach,而不是直接操作枚举数。

枚举器可用于读取集合中的数据,但不能用于修改基础集合。

最初,枚举数定位在集合中第一个元素的前面。 在此位置,属性 Current 未定义。 因此,在读取 的值Current之前,必须调用 MoveNext 方法来将枚举器推进到集合的第一个元素。

在调用 Current 之前,MoveNext 返回相同的对象。 MoveNextCurrent 设置为下一个元素。

如果 MoveNext 传递集合的末尾,则枚举器位于集合中最后一个元素之后,并 MoveNext 返回 false。 当枚举器位于此位置时,对 MoveNext 的后续调用也会返回 false。 如果最后一次MoveNext调用返回 ,falseCurrent则为未定义。 不能再次将 设置为 Current 集合的第一个元素;必须改为创建新的枚举器对象。

只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),枚举器将不可恢复地失效,并且下一次InvalidOperationException调用 MoveNextIEnumerator.Reset 将引发 。

枚举器不具有对集合的独占访问权限;因此,通过集合枚举本质上不是线程安全的过程。 若要确保枚举过程中的线程安全性,可以在整个枚举过程中锁定集合。 若要允许多个线程访问集合以进行读写操作,则必须实现自己的同步。

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> 实例所需的数据。

适用于