You implement IEnumerable<Vehicle> , a generic interface that is strongly typed to store Vehicle objects. This interface, however, derives from an earlier IEnumerable interace, which is not shared, and is typed to hold object object .
If you want to implement a generic version (what you are doing), you also need to implement a non-generic version. Typically, you implement a non-generic GetEnumerator by simply invoking the generic version.
In addition, you probably do not want to explicitly implement GetEnumerator<Vehicle> like you do; this will require you to explicitly use your objects for IEnumerable<Vehicle> to use them. Instead, you probably want to do this:
public IEnumerator<Vehicle> GetEnumerator() { foreach( Vehicle item in items ) { yield return item; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
Michael edenfield
source share