|
-
May 2nd, 2008, 12:26 PM
#1
Thread Starter
Addicted Member
[2005] Last in First Out arraylist
I need to add items to an arraylist until the count gets to, for example, 100 and then read them on a Last in first out basis.
ow do I achieve this?
-
May 2nd, 2008, 12:39 PM
#2
Re: [2005] Last in First Out arraylist
First off, in VB 2005, you should never use the ArrayList, if you need a collection you should use the List(Of T).
However, in this scenario, you should use a collection that is created for this purpose:
VB.NET Code:
System.Collections.Generic.Stack(Of T)
-
May 2nd, 2008, 12:42 PM
#3
Re: [2005] Last in First Out arraylist
Before add an item to your array list, you check the Count property to see if it reaches the limit. If it doesn't, add the item. Else, don't add. Now to read the items LIFO, you just need a For loop running backward from arraylist.count - 1 to 0.
EDIT: If you can use something other than an arraylist, I strongly suggest you to use a stack as Atheist said.
Last edited by stanav; May 2nd, 2008 at 12:47 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|