Class ListEnumerator<T>
A custom enumerator that simply iterates over a List. It differs from C#'s built-in iterator in that it also implements IEnumerable, and so can be used as a substitute for IEnumerable<T>.
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class ListEnumerator<T> : ValueType, IEnumerator<T>, IEnumerator, IDisposable, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | Type of items in the list. |
Remarks
This type is a struct, and as such is much more efficient when used in a foreach loop than a function returning IEnumerable<T>. It is also faster than iterating over a list via an IReadOnlyList reference (about 7x faster, in fact, for types with a small size).
Otherwise, it has basically the same characteristics that exposing a list as IEnumerable<T> would; so if you need to expose items as some type like IEnumerable, and the items are internally stored as a list, this can be a good option. This type does implement IEnumerable, and as such can be used directly with functions that require one (for example, System.LINQ). However, this will have reduced performance due to boxing of the iterator.
Constructors
ListEnumerator(List<T>)
Constructor.
Declaration
public ListEnumerator(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | List to iterate over. |
Properties
Current
Declaration
public T Current { get; }
Property Value
Type | Description |
---|---|
T |
Methods
Dispose()
Declaration
public void Dispose()
GetEnumerator()
Returns this enumerator.
Declaration
public ListEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
ListEnumerator<T> | This enumerator. |
MoveNext()
Declaration
public bool MoveNext()
Returns
Type | Description |
---|---|
Boolean |