iterating through an array
Posted
by Farstucker
on Stack Overflow
See other posts from Stack Overflow
or by Farstucker
Published on 2010-06-15T20:12:58Z
Indexed on
2010/06/15
20:22 UTC
Read the original article
Hit count: 272
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;
}
© Stack Overflow or respective owner