I. Answer
You can use foreach to traverse the accessed objects.IenumerableInterface or declarationGetenumeratorMethod Type
Note: you do not have to implement the ienumerable interface, but you must implement the getenumrator method.
Ii.. NET 1.0 implementation
Code
Public class mylist <t>: ienumerable
{
Public int count {get {return items = NULL? 0: items. Length ;}}
Public T [] items {Get; set ;}
Public t this [int Index]
{
Get {return items [Index];}
}
// Returns the number of enumerations of a set of circular access.
Public ienumerator getenumerator ()
{
Return new myenumerator <t> () {list = this };
}
}
Public class myenumerator <t>: ienumerator
{
Private int Index =-1;
Public mylist <t> List {Get; set ;}
// Set the enumeration number to its initial position before the first element in the set.
Public void reset ()
{
Index =-1;
}
// Push the number of enumerations to the next element of the set.
Public bool movenext ()
{
Index ++;
Return (index <list. Count );
}
// Obtain the current element in the set.
Public object current {get {return list [Index];}
}
// Client call. Note: no generic type exists in 1.0.
Mylist <int> List = new mylist <int> () {items = new int [] {1, 2, 3, 4 }};
Foreach (INT item in List)
{
MessageBox. Show (item. tostring ());
}