Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0482 ToList

public void Linq55() { string[] words = { "cherry", "apple", "blueberry" }; var sortedWords = from w in words orderby w select w; var wordList = sortedWords.ToList(); Console.WriteLine("The sorted word list:"); foreach (var w in wordList) { Console.WriteLine(w); } } Result The sorted word list: apple blueberry cherry