Examples of methods that must be implemented for the IEnumerable interface.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class AnimalFarm : IEnumerable { private List<Animal> animalList = new List<Animal>(); public AnimalFarm(List<Animal> animalList) { this.animalList = animalList; } public AnimalFarm() { } public Animal this[int index] { get { return (Animal)animalList[index]; } set { animalList.Insert(index, value); } } public int Count { get { return animalList.Count; } } IEnumerator IEnumerable.GetEnumerator() { return animalList.GetEnumerator(); } } |
