We help IT Professionals succeed at work.

Maintain strict FIFO

Tom Knowlton
Tom Knowlton asked
I need a list that will maintain a strict FIFO order of items added to it.

Does a List< > do this?  Or can the order get altered?
Watch Question

Research & Development Manager
The List<T> collection can have indexes removed at a given point using List<T>.RemoveAt(index) along with other methods.

Take a look at the Queue<T> collection:  http://www.dotnetperls.com/queue
You control with a list or an array or whatever object you want to use in this type of instance whether it's FIFO.

If you use List<T>.Add to put new items in, and control the loop or however you get things out then its FIFO.

for(t in List<T>)
//do something with t
//t's should be rolled through in the order they were added

If you do List<T>.Reverse or loop through it decrementally then its no longer FIFO ...it might be FIDO though :)
Tom KnowltonWeb developer



I think I was looking for Queue< >

well that's kinda cool, never seen that. learn something new everyday if you're lucky.