Information Technology Reference
In-Depth Information
For example, the following code implements an enumerator class that lists an array of
color names:
using System.Collections;
class ColorEnumerator: IEnumerator
{
string[] Colors;
int Position = -1;
public object Current { // Current
get { return Colors[Position]; }
}
public bool MoveNext() { // MoveNext
if (Position < Colors.Length - 1)
{ Position++; return true; }
else
return false;
}
public void Reset(){ // Reset
Position = -1;
}
public ColorEnumerator(string[] theColors) // Constructor
{
Colors = new string[theColors.Length];
for (int i = 0; i < theColors.Length; i++)
Colors[i] = theColors[i];
}
}
Search WWH ::




Custom Search