Solved

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

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

thank you in advance.
0
Comment
Question by:toshi_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Expert Comment

by:p_davis
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.
0
 
LVL 22

Accepted Solution

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

foreach(MyObj anObj in ArrayList){
    anObj.method();
     ArrayList[index].method();
     index++;                                  <- how can i catch the following objt in the same bloc?
}
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Introduction to Processes
Starting up a Project

688 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