class CustomList<T> : IList<T> {
List<T> StorageList;
public int Count{ get => StorageList.Count; }
public bool IsReadOnly { get => false; }
public CustomList() {
StorageList = new List<T>();
}
public CustomList(IEnumerable<T> collection) {
StorageList = new List<T>(collection);
}
public CustomList(int capacity) {
StorageList = new List<T>(capacity);
}
public void Add(T item) {
StorageList.Add(item);
}
public void Clear() {
StorageList.Clear();
}
public bool Contains(T item) {
return StorageList.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex) {
StorageList.CopyTo(array, arrayIndex);
}
public List<T>.Enumerator GetEnumerator() {
return StorageList.GetEnumerator();
}
public int IndexOf(T item) {
return StorageList.IndexOf(item);
}
public void Insert(int index, T item) {
StorageList.Insert(index, item);
}
public bool Remove(T item) {
return StorageList.Remove(item);
}
public void RemoveAt(int index) {
StorageList.RemoveAt(index);
}
public T this[int index] {
get => StorageList[index];
set => StorageList[index] = value;
}
}
Here my class which implemetns IList<T>
interface from System.Collections.Generic
.
This codes causes CS0738
and according to CS0738
, I didn't implement IEnumerable<T>.GetEnumerator()
.
'CustomList<T>' does not implement interface member 'IEnumerable<T>.GetEnumerator()'. 'CustomList<T>.GetEnumerator()' cannot implement 'IEnumerable<T>.GetEnumerator()' because it does not have the matching return type of ' IEnumerator<T>'.
I can't redefine GetEnumerator()
because I defined it to implement IList<T>.GetEnumerator()
. How should I implement IEnumerable<T>.GetEnumerator()
?