Created
September 29, 2020 16:12
-
-
Save xepherys/f40c61b368614bec3e735903fe469063 to your computer and use it in GitHub Desktop.
RollingList Type that will move the indexer back to 0 when the end of the list is reached.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RollingList<T> : List<T> | |
{ | |
private int indexer = 0; | |
private int maxIndexer; | |
public RollingList() : base() | |
{ | |
maxIndexer = this.Count; | |
} | |
public RollingList(List<T> list) | |
{ | |
foreach (var v in list) | |
this.Add(v); | |
maxIndexer = this.Count; | |
} | |
public new void Add(T item) | |
{ | |
base.Add(item); | |
maxIndexer = this.Count; | |
} | |
public new void Remove(T item) | |
{ | |
base.Remove(item); | |
maxIndexer = this.Count; | |
} | |
public T Next() | |
{ | |
T _ret = this[indexer]; | |
if (indexer + 1 > maxIndexer - 1) | |
indexer = 0; | |
else | |
indexer++; | |
return _ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment