Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0456 OrderBy - Simple 2

public void Linq29() { string[] words = { "cherry", "apple", "blueberry" }; var sortedWords = from w in words orderby w.Length select w; Console.WriteLine("The sorted list of words (by length):"); foreach (var w in sortedWords) { Console.WriteLine(w); } } Result The sorted list of words (by length): apple cherry blueberry