Last active
February 11, 2020 22:51
-
-
Save evanricard/9573f7578fb561ce28e1b0a6bc6e9166 to your computer and use it in GitHub Desktop.
CollectAndEnumerate
This file contains 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
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