class MyStack : ICollection, IEnumerable, IEnumerator { private object[] myArray = new object[0]; private int currentINDEX = 0, foreachIndex = 0; public object Pop() { object o = myArray[myArray.Length - 1]; Array.Resize(ref myArray, myArray.Length - 1); currentINDEX--; return o; } public void Push(object obj) { Array.Resize(ref myArray, myArray.Length + 1); myArray[currentINDEX++] = obj; } public int Count { get { return myArray.Length; } } public object SyncRoot => throw new NotImplementedException(); public bool IsSynchronized => throw new NotImplementedException(); object IEnumerator.Current { get { return myArray[foreachIndex++]; } } public void CopyTo(Array array2, int index) { for (int i = index; i < myArray.Length; i++) { array2.SetValue(myArray[i], i - index); } } public IEnumerator GetEnumerator() { return this; } public bool MoveNext() { if (myArray.Length - 1 == foreachIndex) { return false; } return true; } public void Reset() { foreachIndex = 0; } }