![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Loop only the last 10 items in arraylist Hi, I have an ArrayList, mHistoryDataList, whose Count is 200. However, I only want to loop through the last 10 items on mHistoryDataList. That is, to loop mHistoryDataList, as if the first 190 items didn't exist. How can I do this in a "foreach" statement? foreach (Daily daily in hist.HistoryData) { // Start from 191th item } Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Loop only the last 10 items in arraylist Well you probably should not use a ArrayList, use a generic collection instead. Then one way is to use a regular For loop and just start and end at the last 20 items. using System.Collections.ObjectModel; private void Test() { Collection<String> items = CreateItems(); for (int t = items.Count - 20; t < items.Count; t++) { String item=items[t]; System.Diagnostics.Debug.WriteLine(item); } } private Collection<String> CreateItems() { Collection<String> items = new Collection<string>(); for (int t = 0; t < 40; t++) { items.Add("Test "+t.ToString()); } return items; } Eric "Curious" <fir5tsight@xxxxxx> wrote in message news:f638db24-3f37-4685-b945-b4a9fd40e518@xxxxxx Quote: > Hi, > > I have an ArrayList, mHistoryDataList, whose Count is 200. However, I > only want to loop through the last 10 items on mHistoryDataList. > > That is, to loop mHistoryDataList, as if the first 190 items didn't > exist. How can I do this in a "foreach" statement? > > foreach (Daily daily in hist.HistoryData) > { > // Start from 191th item > } > > Thanks! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Loop only the last 10 items in arraylist Thanks for the advice. It works! |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Loop only the last 10 items in arraylist Curious wrote: foreach (Daiy daily in hist.HistoryData.GetRange(191, 10)) { // blah } |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How can I destroy objects like an ArrayList? | PowerShell | |||
| Remove items from ArrayList | .NET General | |||
| Get the last item in ArrayList | .NET General | |||
| Marshalling ArrayList | .NET General | |||
| Thread-safety: Change property of items in arraylist versus removingitems from the arraylist | .NET General | |||