LinkedList<string>.ToArray() ?

is there a way to do the equivalent of these in 2.0:
List<string>.InsertBefore()
List<string>.InsertAfter()
List<string>.InsertAt()
I also tried using LinkedList<>, but I can't find this method:
LinkedList<string>.ToArray()
[280 byte] By [MarkA.Richman] at [2008-1-27]
# 1

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);

HeathStewart at 2007-9-8 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 2

You can actually do this:


List<string> list = new List<string>()

list.Add("World");
list.Insert(0, "Hello");
list.Insert(2, "1");

DavidM.Kean at 2007-9-8 > top of Msdn Tech,.NET Development,Common Language Runtime...

.NET Development

Site Classified