On Sun, 1 Feb 2004 15:59:58 +0100, "Arjen" <bo*****@hotmail.com>
wrote:
Hello,
I have a this:
foreach ( string s in myArray ) {
if ( s == ""test") {
}
}
How can I read the next "s" (if there is a next one) inside the current
readed "s"?
Thanks!
Arjen
A foreach loop is designed to loop through a collection and only
expose one item in the collection at a time. What you can do, is
change the logic in something like this:
string[] arrItems = new string[5];
arrItems[0] = "test0";
arrItems[1] = "test1";
arrItems[2] = "test2";
arrItems[3] = "test3";
arrItems[4] = "test4";
string strPrevious = null;
foreach (string str in arrItems)
{
if (strPrevious != null)
{
// strPrevious is the previous item
// str is the current item
}
strPrevious = str;
}
--
Ludwig