• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

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

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
Erwin Pombett
Asked:
Erwin Pombett
  • 2
1 Solution
 
p_davisCommented:
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
 
p_davisCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now