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();
        }
posted on 2012-06-06 14:26  HWwayne  阅读(454)  评论(0)    收藏  举报