[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • 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
toshi_
Asked:
toshi_
  • 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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