Does a List guarantee that items will be returned in the order they were added?

The List is index based and new items will always be added to the end of the list. You can insert items at a certain index so the next items will move one position.

So yes, you can use it safely that way…

The List(T) class is the generic
equivalent of the ArrayList class. It
implements the IList(T) generic
interface using an array whose size is
dynamically increased as required.

Elements in this collection can be
accessed using an integer index.
Indexes in this collection are
zero-based.

The List(T) is not guaranteed to be
sorted. You must sort the List(T)
before performing operations (such as
BinarySearch) that require the List(T)
to be sorted.

A List(T) can support multiple readers
concurrently, as long as the
collection is not modified.
Enumerating through a collection is
intrinsically not a thread-safe
procedure. In the rare case where an
enumeration contends with one or more
write accesses, the only way to ensure
thread safety is to lock the
collection during the entire
enumeration. To allow the collection
to be accessed by multiple threads for
reading and writing, you must
implement your own synchronization.

You can read more about it on MSDN.

Leave a Comment