C#的LINQ进行分组和排序

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

 
namespace ConsoleApplication1
{
    class Program
    {   
        static void Main(string[] args)
        {
            string[] words = { "hello", "wonderful", "linq", "beautiful", "world" ,"csdn","qiushi07","hao","microsoft","google","facebook","haha","sb","who","where"};
            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 group in groups)
            {
                Console.Write

你可能感兴趣的:(C#,C#开发)