views:

69

answers:

3

I need to copy an array to a linked list OR transform the array in a linked list.

How this can be done in .NET (C# or VB)?

Thanks

+5  A: 

Depending on what version we're taking about here, you can :

LinkedList<YourObjectType> ListOfObjects=new LinkedList<YourObjectType>(YourObjectArray);
Ian Jacobs
Pretty simple. Thanks!
RHaguiuda
+2  A: 

In .Net v2.0 or above:

Object[] myArray = new Object[] { 1, "Hello", 2, 3.0 };
LinkedList<Object> linkedList = new LinkedList<Object>(myArray);

You can replace Object with the type of element that the array actually holds.

codekaizen
A: 

To go to LinkedList from array:

var array = GetMyArray();
LinkedList<MyType> list = new LinkedList<MyType>(array);

To go to array from LinkedList:

var array = list.ToArray();
Reed Copsey