Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, July 22, 2012 5:29 PM
Can a LinkedList be converted to a List? I have a method whose return is a List. I want to create a LinkedList within the method and return it as a List. Is there another way to do it?
REvans
All replies (6)
Wednesday, July 25, 2012 2:32 PM âś…Answered
Please check this example
string[] words = { "the", "fox", "jumped", "over", "the", "dog" };LinkedList<String> myQueue = new LinkedList<string>(words);List<String> myList = new List<string>(myQueue);foreach (var item in myList) { Console.WriteLine(item); }
With Thanks and Regards
Sambath Raj.C
click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
Happy Programming!
Sunday, July 22, 2012 5:40 PM
Have you tried to add "ToList()" on the end of object?
This how:
LinkedList<string> linkedList = new LinkedList<string>();
linkedList.AddLast("a");
linkedList.AddLast("b");
linkedList.AddLast("c");
linkedList.ToList();
Mitja
Wednesday, July 25, 2012 2:04 PM
My linkedlist doesn't have the option to add .ToList();
REvans
Wednesday, July 25, 2012 2:19 PM
return new List<T>(LinkedList<T>)
Wednesday, July 25, 2012 2:50 PM | 2 votes
My linkedlist doesn't have the option to add .ToList();
REvans
It's a LINQ extension method. You will need to add a "using" statement for System.Linq.
Wednesday, July 25, 2012 2:53 PM | 1 vote
My linkedlist doesn't have the option to add .ToList();
REvans
It's a LINQ extension method. You will need to add a "using" statement for System.Linq.
Maybe he is using VS older then 2008.
Mitja