IEnumerator<T>

IEnumerator<T>は、ジェネリクス版のIEnumerator。

https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.ienumerator-1?view=netframework-4.8

<T>のないIEnumeratorとIDisposableの各メンバを実装しないといけない。

TestEnumeratorのコンストラクタで配列を受け取り、こちらのメンバで操作していく。
Tを返すCurrentでindex-1番目を返す。IEnumerator.Currentは実装してるが、使ってない。
あとは基底のメンバを実装。

TestCollectionのコンストラクタでTの配列を渡してTestEnumeratorを使っている。

今度は5つの文字列をセット。

IEnumerator<T> GetEnumerator()
MoveNext, index = 0
IEnumerator<T>:index = 0, Current = A
value = A
MoveNext, index = 1
IEnumerator<T>:index = 1, Current = B
value = B
MoveNext, index = 2
IEnumerator<T>:index = 2, Current = C
value = C
MoveNext, index = 3
IEnumerator<T>:index = 3, Current = D
value = D
MoveNext, index = 4
IEnumerator<T>:index = 4, Current = E
value = E
続行するには何かキーを押してください . . .

MoveNext, IEnumerator<T>のCurrentなどが呼ばれているのがわかる。

Sample/dotnet/IEnumerator_T/IEnumerator_T/src/IEnumerator_T_ at master · bg1bgst333/Sample · GitHub