Solved

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

Posted on 2009-04-01
2
169 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_
  • 2
2 Comments
 
LVL 22

Expert Comment

by:p_davis
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 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

10 Experts available now in Live!

Get 1:1 Help Now