I declare following object
List<string> list = {"Kate", "John", "Paul", "Eve", "Hugo"};
I would like to move “Eve” at front of my list? How can I do that. I must not to reorder other elements!
At output I want to get this
"Eve", "Kate", "John", "Paul", "Hugo"
However, if your list contains multiple “Eve”s, calling Remove(“Eve”) will only remove the first occurrence of “Eve”.
And you have to know that inserting element at the beginning of a list is an expensive operation. Because all elements already in the list have to be shifted.
UPDATE
As @AlvinWong commented,
LinkedList<string>is a very good solution to avoid this overhead when inserting an element. TheInsertoperation is done in O(1) (O(n-i) in aList). The major drawback ofLinkedList<string>is that accessing theith element is an operation in O(i) (O(1) in aList).