Well spotted Bary, i noticed that bug after oops. the second and last
startPos whould have been 'i' . Guess you all realised that?
I can use the two loops but once i find the one i want i want to break. The
two loops would almost certainly result in the same elements being checked
at some point, a bit inefficient? Though i am being picky.
For the enumeration class methodology.
Does that allow for me to iterate through an array o any type and it will
check every element starting at my start pos, going to the end and then if
it doesnt find it going back to the start and checking the final ones.
Breaking the moment it finds the one i need. So i can put my conditional
part inside the braces of the foreach statement?
I am going to try it. Althought it uses two for loops it does make for very
neat code which i like. Thanks for such a detailed answer, i have never seen
the 'yield' term before, how does this differ from return?
Thanks!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uP******** ******@TK2MSFTN GP03.phx.gbl...
Daniel,
I think the best solution is to have a class do this for you. It
actually becomes VERY easy using generics and anonymous iterators. I've
attached a sample class for you to use (and a little demo program) which
will show you how you can make it much easier.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Daniel" <Da*****@vestry online.com> wrote in message
news:uY******** ******@TK2MSFTN GP04.phx.gbl... Hey guys
i have a array of daya that i wish to iterate through. the only catch is
i
need to start from a certain position but on reaching the end of the
array
go back to the start and do the rest so that on ever loop every element
is
checked in the right order.
For example
int totalCount=0; //to internally track total elements parsed
for(int i=startPos; i<numberOfPlaye rs; i++)
{
//loop through checking for condition and breaking loop if found
totalCount++;
if(totalCount >= numberOfPlayers ) //if we have checked them all
stop
looping
break;
else if( startPos.Equals (numberOfPlayer s-1) ) //if we reached the
end but have not checked them all restart from beginning
startPos = 0; //to reset to start
}
There must be a better way than the above solution?
thanks