An object, if it can provide references to related objects, is a collection, called an enumeration, that iterates through the items in the collection. The collection must perform an interface System.Collentions.LEnumerable, lenumerable defines only one method, as follows:
Interface Ienumeralbe
{
IEnumerator GetEnumerator ();
}
IEnumerator works as follows: The object that executes the interface is associated with a collection that, at the first initialization, does not yet point to any element in the collection, and must call MoveNext () to move the enumeration so that it points to the first element in the collection. Then you get the element with the current property, and the current property returns an object reference, so you must convert its data type to the type of object you are looking for in the collection. You can take any action on the object again, and then call the MoveNext () method again to move to the next element of the collection, repeating the procedure until there is no element in the collection, and when the current property returns NULL, it indicates that the end of the collection has been reached. If you want to return to the beginning of the collection at any time, you can call the Reset () method. Note that the reset () method returns the position of the front of the collection <?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>
Arrays are also collections, because the foreach command can act on an array. For an enumerated array provided by the System.Array class, you can iterate through the elements in ascending order starting with the subscript 0.