ReadOnlySpan.Enumerator Struct
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides an enumerator for the elements of a ReadOnlySpan
public: value class ReadOnlySpan::Enumerator : System::Collections::Generic::IEnumerator
public: value class ReadOnlySpan::Enumerator
public ref struct ReadOnlySpan.Enumerator : System.Collections.Generic.IEnumerator
public ref struct ReadOnlySpan.Enumerator
type ReadOnlySpan<'T>.Enumerator = struct
interface IEnumerator<'T>
interface IEnumerator
interface IDisposable
type ReadOnlySpan<'T>.Enumerator = struct
Public Structure ReadOnlySpan(Of T).Enumerator
Implements IEnumerator(Of T)
Public Structure ReadOnlySpan(Of T).Enumerator
Type Parameters
- T
- Inheritance
- Implements
Remarks
The C# foreach of the C# language and the For Each...Next construct in Visual Basic hides the complexity of enumerators. Instead of directly manipulating the enumerator, using foreach or For Each...Next is recommended.
Initially, the enumerator is positioned before the first element in the ReadOnlySpan
Current returns the same value until MoveNext is called. MoveNext sets Current to the next item in the ReadOnlySpan
If MoveNext passes the end of the ReadOnlySpanfalse. When the enumerator is at this state, subsequent calls to MoveNext also return false and Current is undefined. You cannot set Current to the first item in the ReadOnlySpan
Though the ReadOnlySpan
Unlike some other enumerator structures in .NET, the ReadOnlySpan
Does not implement the IEnumerator or IEnumerator
interface. This is because ReadOnlySpan .Enumerator is a ref struct and cannot be boxed.Does not include a
Resetmethod, which can set the enumerator to its initial position before the first element in the span. (The IEnumerator.Reset() method must be implemented as part of the interface, but most implementors either throw an exception or provide no implementation.)
Properties
| Name | Description |
|---|---|
| Current |
Gets a reference to the item at the current position of the enumerator. |
Methods
| Name | Description |
|---|---|
| MoveNext() |
Advances the enumerator to the next item of the ReadOnlySpan |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IDisposable.Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| IEnumerator.Current |
Gets the element in the collection at the current position of the enumerator. |
| IEnumerator.Reset() |
Sets the enumerator to its initial position, which is before the first element in the collection. |
|
IEnumerator |
Gets the element in the collection at the current position of the enumerator. |