You do that by inserting into position 0:
List myList = new List();
myList.Insert(0, "test");
Use Insert
method:
list.Insert(0, item);
Of course, Insert
or AddFirst
will do the trick, but you could always do:
myList.Reverse();
myList.Add(item);
myList.Reverse();
Use List.Insert(0, ...)
. But are you sure a LinkedList
isn't a better fit? Each time you insert an item into an array at a position other than the array end, all existing items will have to be copied to make space for the new one.
Use List<T>.Insert(0, item)
or a LinkedList<T>.AddFirst()
.
myList.Insert(0, item);
Source: Stackoverflow.com