Circular Collection?

  • Thread starter Thread starter Joel Moore
  • Start date Start date
J

Joel Moore

Is there a predefined collection in .NET that allows you to index through
its values by simply using a "NextItem" function (where it keeps track of
the currently referenced item) and wraps around so that you return to the
first item after reaching the end? Or is this something I'll just have to
write myself?

Thanks,

Joel Moore
 
Is there a predefined collection in .NET that allows you to index through
its values by simply using a "NextItem" function (where it keeps track of
the currently referenced item) and wraps around so that you return to the
first item after reaching the end? Or is this something I'll just have to
write myself?


With such a collection, a forech loop would be an endless loop.
However, such a collection does currently not exist you have to write it
yourself, maybe not a whole collection but an Enumerator.

if you enumerate over a simple arraylist you can implement the MoveNext
method of the enumerator the following:

public void MoveNext()
{
if (index==arraylist.Count-1)
index = 0;
else
index++;
}
 
Back
Top