Queue<T>.Enumerator Struktura
Definice
public: value class Queue<T>::Enumerator : System::Collections::Generic::IEnumerator<T>
public struct Queue<T>.Enumerator : System.Collections.Generic.IEnumerator<T>
[System.Serializable]
public struct Queue<T>.Enumerator : System.Collections.Generic.IEnumerator<T>
type Queue<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IEnumerator
interface IDisposable
[<System.Serializable>]
type Queue<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IDisposable
interface IEnumerator
[<System.Serializable>]
type Queue<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IEnumerator
interface IDisposable
Public Structure Queue(Of T).Enumerator
Implements IEnumerator(Of T)
Parametry typu
- T
- Dědičnost
- Atributy
- Implementuje
Poznámky
foreach
Příkaz jazyka C# ( for each
v jazyce C++, For Each
v Visual Basic) skrývá složitost enumerátorů.The foreach
statement of the C# language (for each
in C++, For Each
in Visual Basic) hides the complexity of the enumerators. Proto foreach
se doporučuje použít místo přímé manipulace s enumerátorem.Therefore, using foreach
is recommended, instead of directly manipulating the enumerator.
Enumerátory lze používat ke čtení dat v kolekci, nikoli však k úpravě zdrojové kolekce.Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.
Zpočátku je enumerátor umístěn před první prvek v kolekci.Initially, the enumerator is positioned before the first element in the collection. Na této pozici Current není definován.At this position, Current is undefined. Proto je nutné zavolat MoveNext pro pokračování enumerátoru na první prvek kolekce před čtením hodnoty Current .Therefore, you must call MoveNext to advance the enumerator to the first element of the collection before reading the value of Current.
Currentvrátí stejný objekt, dokud MoveNext není volán.Current returns the same object until MoveNext is called. MoveNextnastaví Current na další prvek.MoveNext sets Current to the next element.
Pokud MoveNext předá konec kolekce, enumerátor je umístěn za posledním prvkem v kolekci a MoveNext vrátí false
.If MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns false
. Když je na této pozici enumerátor, následné volání MoveNext vrátí také false
.When the enumerator is at this position, subsequent calls to MoveNext also return false
. Pokud poslední volání MoveNext vráceno false
Current není definováno.If the last call to MoveNext returned false
, Current is undefined. Nemůžete nastavit Current na první prvek kolekce znovu. místo toho je nutné vytvořit novou instanci enumerátoru.You cannot set Current to the first element of the collection again; you must create a new enumerator instance instead.
Enumerátor zůstává platný, dokud kolekce nezůstane beze změny.An enumerator remains valid as long as the collection remains unchanged. Pokud jsou provedeny změny v kolekci, jako je například přidání, úprava nebo odstranění prvků, enumerátor je nevratně Neověřeno a další volání MoveNext nebo vyvolá výjimku IEnumerator.Reset InvalidOperationException .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.
Enumerátor nemá výhradní přístup k této kolekci; Proto výčet prostřednictvím kolekce je vnitřně nebezpečný pro přístup z více vláken.The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Pro zajištění bezpečnosti vlákna během výčtu můžete kolekci uzamknout během celého výčtu.To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. Chcete-li více vláknům umožnit přístup ke kolekci pro čtení a zápis, musíte implementovat svou vlastní synchronizaci.To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
Výchozí implementace kolekcí v nástroji System.Collections.Generic se nesynchronizují.Default implementations of collections in System.Collections.Generic are not synchronized.
Vlastnosti
Current |
Získá prvek na aktuální pozici čítače výčtu.Gets the element at the current position of the enumerator. |
Metody
Dispose() |
Uvolní všechny prostředky, které používá Queue<T>.Enumerator .Releases all resources used by the Queue<T>.Enumerator. |
MoveNext() |
Posune enumerátor k dalšímu prvku Queue<T> .Advances the enumerator to the next element of the Queue<T>. |
Explicitní implementace rozhraní
IEnumerator.Current |
Získá prvek na aktuální pozici čítače výčtu.Gets the element at the current position of the enumerator. |
IEnumerator.Reset() |
Nastaví enumerátor na jeho počáteční pozici, která je před prvním prvkem v kolekci.Sets the enumerator to its initial position, which is before the first element in the collection. |