Using a List<> allows you to add items to the end of the collection and uses an array internally, which is why you can't add items at certain places (you could, but that would be a very expensive operation since you'd have to shift array elements with each insertion).
A LinkedList<> uses references to the next element and allows you to inexpensively insert items anyway.
If you want to copy the contents of a LinkedList<string> to a string[] array, you can use the CopyTo() method:
LinkedList<string> list = new LinkedList<string>(); list.AddAfter(list.AddHead("One"), "Two"); string[] array = new string[list.Count]; list.CopyTo(array, 0);
LinkedList<string>.ToArray() ???
Lokka
You can actually do this:
List<string> list = new List<string>()
list.Add("World");
list.Insert(0, "Hello");
list.Insert(2, "1");
G3rTrunk3n
Using a List<> allows you to add items to the end of the collection and uses an array internally, which is why you can't add items at certain places (you could, but that would be a very expensive operation since you'd have to shift array elements with each insertion).
A LinkedList<> uses references to the next element and allows you to inexpensively insert items anyway.
If you want to copy the contents of a LinkedList<string> to a string[] array, you can use the CopyTo() method:
LinkedList<string> list = new LinkedList<string>();
list.AddAfter(list.AddHead("One"), "Two");
string[] array = new string[list.Count];
list.CopyTo(array, 0);