排序操作按一个或多个特性对序列的元素进行排序。 第一个排序条件对元素执行主要排序。 通过指定第二个排序条件,可以对各个主要排序组中的元素进行排序。
string[] words = { "the", "quick", "brown", "fox", "jumps" };
IEnumerable<string> query = from word in words orderby word.Length select word;
foreach (string str in query) Console.WriteLine(str);
|
string[] words = { "the", "quick", "brown", "fox", "jumps" };
IEnumerable<string> query = from word in words orderby word.Substring(0, 1) descending select word;
foreach (string str in query) Console.WriteLine(str);
|
string[] words = { "the", "quick", "brown", "fox", "jumps" };
IEnumerable<string> query = from word in words orderby word.Length, word.Substring(0, 1) select word;
foreach (string str in query) Console.WriteLine(str);
|
string[] words = { "the", "quick", "brown", "fox", "jumps" };
IEnumerable<string> query = from word in words orderby word.Length, word.Substring(0, 1) descending select word;
foreach (string str in query) Console.WriteLine(str);
|