public class MyList : IEnumerable
public int[] _data = new int[10] { 1, 5, 7, 9, 7, 8, 7, 8, 7, 4 };
public int this[int index]
return _data[index];
IEnumerator IEnumerable.GetEnumerator()
Debug.Log("foreach调用 GetEnumerator");
return new MIEnumtor(this);
public class MIEnumtor : IEnumerator
private MyList myList;
private int index;
public MIEnumtor(MyList my)
index = -1;
myList = my;
public object Current
Debug.Log("foreach调用 Current");
return myList[index];
public bool MoveNext()
Debug.Log("foreach调用 MoveNext");
if (index < myList._data.Length - 1)
index++;
return true;
index = -1;
return false;
public void Reset()