SortedSet<T>.Enumerator Struktur
Definition
Listet die Elemente eines SortedSet<T>-Objekts auf.Enumerates the elements of a SortedSet<T> object.
public: value class 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 ISerializable
interface IDeserializationCallback
interface IDisposable
Public Structure SortedSet(Of T).Enumerator
Implements IDeserializationCallback, IEnumerator(Of T), ISerializable
Typparameter
- T
- Vererbung
- Attribute
- Implementiert
Hinweise
Die foreach
-Anweisung der C# for each
Sprache( in C++verbirgt die Komplexität von Enumeratoren. For Each
The foreach
statement of the C# language (for each
in C++, For Each
in Visual Basic) hides the complexity of enumerators. Daher empfiehlt es sich, foreach
zu verwenden und den Enumerator nicht direkt zu ändern.Therefore, using foreach
is recommended, instead of directly manipulating the enumerator.
Mit Enumeratoren können die Daten in der Auflistung zwar gelesen, jedoch nicht zum Ändern der zugrunde liegenden Auflistung verwendet werden.Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.
Zu Beginn wird der Enumerator vor das erste Element in der Auflistung positioniert.Initially, the enumerator is positioned before the first element in the collection. An dieser Position ist die Current -Eigenschaft nicht definiert.At this position, the Current property is undefined. Daher muss die MoveNext -Methode aufgerufen werden, um den Enumerator vor dem Lesen des Werts von Currentauf das erste Element der Auflistung zu setzen.Therefore, you must call the MoveNext method to advance the enumerator to the first element of the collection before reading the value of Current.
Current gibt solange dasselbe Objekt zurück, bis MoveNext aufgerufen wird.Current returns the same object until MoveNext is called. MoveNext legt Current auf das nächste Element fest.MoveNext sets Current to the next element.
Wenn MoveNext das Ende der Auflistung übergibt, wird der Enumerator hinter dem letzten Element in der Auflistung platziert, und MoveNext gibt false
zurück.If MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns false
. Wenn sich der Enumerator an dieser Position befindet, geben nachfolgende Aufrufe von MoveNext auch false
zurück.When the enumerator is at this position, subsequent calls to MoveNext also return false
. Wenn der letzte Aufruf MoveNext zurückgegebene false
, Current ist nicht definiert.If the last call to MoveNext returned false
, Current is undefined. Sie können nicht Current erneut auf das erste Element der Auflistung festlegen. stattdessen müssen Sie stattdessen ein neues Enumeratorobjekt erstellen.You cannot set Current to the first element of the collection again; you must create a new enumerator object instead.
Ein Enumerator bleibt gültig, solange die Auflistung unverändert ist.An enumerator remains valid as long as the collection remains unchanged. Wenn an der Auflistung Änderungen vorgenommen werden, z. b. das Hinzufügen, ändern oder Löschen von Elementen, wird der Enumerator unwiederbringlich ungültig, MoveNext und IEnumerator.Reset der nächste InvalidOperationExceptionRückruf von oder löst eine aus.If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or IEnumerator.Reset throws an InvalidOperationException.
Der Enumerator hat keinen exklusiven Zugriff auf die Auflistung. Daher ist das Auflisten durch eine Auflistung intrinsisch keine Thread sichere Prozedur.The enumerator doesn't have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Um während der Enumeration Threadsicherheit zu garantieren, können Sie die Auflistung während der gesamten Enumeration sperren.To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. Um den Lese- und Schreibzugriff auf diese Auflistung durch mehrere Threads zuzulassen, müssen Sie eine eigene Synchronisierung implementieren.To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
Standardimplementierungen der Auflistungen im System.Collections.Generic-Namespace werden nicht synchronisiert.Default implementations of collections in the System.Collections.Generic namespace are not synchronized.
Eigenschaften
Current |
Ruft das Element an der aktuellen Position des Enumerators ab.Gets the element at the current position of the enumerator. |
Methoden
Dispose() |
Gibt alle vom SortedSet<T>.Enumerator verwendeten Ressourcen frei.Releases all resources used by the SortedSet<T>.Enumerator. |
MoveNext() |
Setzt den Enumerator auf das nächste Element der SortedSet<T>-Auflistung.Advances the enumerator to the next element of the SortedSet<T> collection. |
Explizite Schnittstellenimplementierungen
IDeserializationCallback.OnDeserialization(Object) |
Implementiert die ISerializable-Schnittstelle und löst das Deserialisierungsereignis aus, sobald die Deserialisierung abgeschlossen ist.Implements the ISerializable interface and raises the deserialization event when the deserialization is complete. |
IEnumerator.Current |
Ruft das Element an der aktuellen Position des Enumerators ab.Gets the element at the current position of the enumerator. |
IEnumerator.Reset() |
Setzt den Enumerator auf seine anfängliche Position vor dem ersten Element in der Auflistung.Sets the enumerator to its initial position, which is before the first element in the collection. |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
Implementiert die ISerializable-Schnittstelle und gibt die zum Serialisieren der SortedSet<T>-Instanz erforderlichen Daten zurück.Implements the ISerializable interface and returns the data needed to serialize the SortedSet<T> instance. |