I have an foreach loop that looks like this
foreach (Student newSortedStudent in studentWithData) { newSortedStudent.Fees = newSortedStudent.Fees.OrderBy......ToArray(); }but now I need to have access to this newSortedStudent object and manipulate with it more.
if I do something like this
foreach (Student newSortedStudent in studentWithData) { newSortedStudent.Fees = newSortedStudent.Fee.OrderBy......ToArray(); } foreach(Student studentData in **newSortedStudent**) { .... }I'll get an error newSortedStudent does not exist in the current context.
So how can I access the newSortedStudent outside of that foreach loop?
Thanks
VulpesPosted Mar 13, 2013, 7:22 AM
However, I don't really understand why you want outside code to have access to the foreach iiteration variable in any case as you won't be able to 'jump back into' the foreach statement and carry on where you left off after outside processing has taken place.
It's best therefore to either carry out the processing inside the foreach loop or to call a method within the loop which does it.
Vidya Vrat AgarwalPosted Mar 13, 2013, 3:43 AM
How about something like this:
student newSortedStudent;
foreach (
newSortedStudent in studentWithData)