14

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

3 Answers 3

29

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

LinkedList<YourObjectType> ListOfObjects=new LinkedList<YourObjectType>(YourObjectArray);
0
10

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();
0
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.