David Chen

David Chen

  • NA
  • 50
  • 45.8k

Access an object outside of a scope

Mar 13 2013 1:59 AM

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


Answers (2)