in a foreach, how can i view the current and the next element in the bloc?

Posted on 2009-04-01
Last Modified: 2013-12-17
i have a foreach loop on an ArrayList,
foreach(MyObj anObj in ArrayList){
                                            <- how can i catch the following objt in the same bloc?

thank you in advance.
Question by:toshi_
  • 2
LVL 22

Expert Comment

ID: 24038598
add an int32 or something outside of the foreach instantiated and set = to 1. then just increment each time in the foreach you can use this to index the next value.
LVL 22

Accepted Solution

p_davis earned 250 total points
ID: 24038604
Int32 index = 1;

foreach(MyObj anObj in ArrayList){
     index++;                                  <- how can i catch the following objt in the same bloc?

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now