Skip to content

Instantly share code, notes, and snippets.

@evanricard
Last active February 11, 2020 22:51
Show Gist options
  • Save evanricard/9573f7578fb561ce28e1b0a6bc6e9166 to your computer and use it in GitHub Desktop.
Save evanricard/9573f7578fb561ce28e1b0a6bc6e9166 to your computer and use it in GitHub Desktop.
CollectAndEnumerate
class Team<T> : IEnumerable<T> // enumerable collection
{
private T[] workers;
private const byte DEFAULTSIZE = 5;
public Team() {
this.workers = new T[DEFAULTSIZE];
}
private int i = 0;
public void Add(T param)
{
this.workers[i++] = param;
i %= workers.Length;
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
foreach (T worker in this.workers)
{
yield return worker;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment