Iterating though an array isn’t a problem but what if I only wanted to incremented only when the method is called?
Im not even sure if this would work but is there an easier way of doing this
int counter;
string[] myArray = {"foo", "bar", "something", "else", "here"};
private string GetNext()
{
string myValue = string.Empty;
if (counter < myArray.Length) {
myValue = myArray [counter];
} else {
counter = 0;
}
counter++;
return myValue;
}
What you want is an iterator
However just calling myArray.GetEnumerator(); has the same effect.
You use it by