Best way to implement a List(Of) with a maximum number of items

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2011-11-14T09:41:57Z Indexed on 2011/11/14 9:50 UTC
Read the original article Hit count: 234

Filed under:

I'm trying to figure out a good way of implementing a List(Of) that holds a maximum number of records.

e.g.

I have a List(Of Int32) - it's being populated every 2 seconds with a new Int32 item.

I want to store only the most current 2000 items.

How can I make the list hold a maximum of 2000 items, then when the 2001'th item is attempted to be added, the List drops the 2000'th item (resulting in the current total being 1999).

Thing is, I need to make sure I'm dropping only the oldest item and adding a new item into the List.

Ben

© Stack Overflow or respective owner

Related posts about list