If the collection is a collection of cars, why won't you just use
public class CarCollection : IEnumerable
Anyway, IEnumerable requires that you would have an IEnumerator
It should be something like this... I didn't compile it, so I'm not sure that it actually compiles good, but its about right I think.
public class CarCollection : IEnumerable
{
List<car> cars;
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator)GetEnumerator();
}
public CarEnum GetEnumerator()
{
return new CarEnum(cars);
}
public class CarEnum : IEnumerator
{
private List<car> cars;
int position = -1;
public CarEnum(List<car> commands)
{
this.cars = cars;
}
public bool MoveNext()
{
position++;
return (position < cars.Count);
}
public void Reset()
{
position = -1;
}
object IEnumerator.Current
{
get
{
return Current;
}
}
public Car Current
{
get
{
try
{
return cars[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
}
</car></car></car>