Show / Hide Table of Contents

Struct 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>.

Implements
IEnumerator<T>
IEnumerator
IDisposable
IEnumerable<T>
IEnumerable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public struct ListEnumerator<T> : 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

View Source

ListEnumerator(List<T>)

Constructor.

Declaration
public ListEnumerator(List<T> list)
Parameters
Type Name Description
List<T> list

List to iterate over.

Properties

View Source

Current

Declaration
public T Current { get; }
Property Value
Type Description
T

Methods

View Source

Dispose()

Declaration
public void Dispose()
View Source

GetEnumerator()

Returns this enumerator.

Declaration
public ListEnumerator<T> GetEnumerator()
Returns
Type Description
ListEnumerator<T>

This enumerator.

View Source

MoveNext()

Declaration
public bool MoveNext()
Returns
Type Description
bool

Implements

IEnumerator<T>
IEnumerator
IDisposable
IEnumerable<T>
IEnumerable

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?, EventHandler<ValueChangedEventArgs<TProperty>>?)
ToStringExtensions.ExtendToString<T>(IEnumerable<T>, string, Func<T, string>?, string, string)
  • View Source
In this article
Back to top Generated by DocFX