static void Main(string[] args) { string[] words = { "hello", "wonderful", "linq", "beautiful", "word" }; var groups = from word in words orderby word ascending group word by word.Length into lengthGroups orderby lengthGroups.Key descending select new { length = lengthGroups.Key, words = lengthGroups }; foreach (var item in groups) { Console.WriteLine("字符串长度="+ item.length); foreach (var s in item.words) { Console.WriteLine("s=" + s); } } Console.ReadKey(); }
浙公网安备 33010602011771号