I have a class with an indexer implemented. I would like to be able to run a foreach loop on the this but it says that I have to implement the Enumerator interface. Which makes me implement two methods:
#region IEnumerable implementation
public IEnumerator<Type> GetEnumerator() {
throw new NotImplementedException();
}
#endregion
#region IEnumerable implementation
IEnumerator IEnumerable.GetEnumerator() {
throw new NotImplementedException();
}
#endregion
- Could you please example me what's the difference between these two?
- What kind of implementation it requires?
The class is built this way:
- It has a field which is an array to keep the data.
- It has an indexer to get and set specific elements in the above mentioned array.
I want to be able to run a foreach loop on the this within the class, so I can get and set the array field using the indexer's get and set logic.
That's why I'm required to implement the GetEnumerator methods, but I have no clue what kind of implementation is required there.
Thanks for you helping.
Note: The How do I implement IEnumerable<T> thread did not help me, I've read it. The only implementation there is to return the array's enumerator.