Struct ListCastEnumerator<TBase, TItem>
A custom enumerator that iterates over a List and casts its objects to the given type.
All objects must be of the specified type, or the iterator will not function.
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public struct ListCastEnumerator<TBase, TItem> : IEnumerator<TItem>, IEnumerator, IDisposable, IEnumerable<TItem>, IEnumerable where TItem : TBase
Type Parameters
Name | Description |
---|---|
TBase | Type items in the list are stored as. |
TItem | Actual 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> or using System.LINQ extensions such as Where.
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 SourceListCastEnumerator(List<TBase>)
Constructor.
Declaration
public ListCastEnumerator(List<TBase> list)
Parameters
Type | Name | Description |
---|---|---|
List<TBase> | list | List to iterate over. |
Properties
View SourceCurrent
Declaration
public TItem Current { get; }
Property Value
Type | Description |
---|---|
TItem |
Methods
View SourceDispose()
Declaration
public void Dispose()
GetEnumerator()
Returns this enumerator.
Declaration
public ListCastEnumerator<TBase, TItem> GetEnumerator()
Returns
Type | Description |
---|---|
ListCastEnumerator<TBase, TItem> | This enumerator. |
MoveNext()
Declaration
public bool MoveNext()
Returns
Type | Description |
---|---|
bool |