C# GroupBy将字符串数组按元素长度分组
代码说明:
C#演示 GroupBy字符串操作范例,C# GroupBy将字符串数组按元素长度分组: string[] Words = new string[] { "what", "is", "your", "name", "?", "my", "name", "is", "lyf", "." }; var Groups = from word in Words group word by word.Length into lengthGroups//按单词长度将单词分组 orderby lengthGroups.Key descending//按单词长度降序排列 select new { Length = lengthGroups.Key,//取单词长度 WordCollect = lengthGroups//取该长度的单词分组集合 };最后使用foreach循环遍历每组单词,将罗列出包括指定字符的单词是哪几个。
下载说明:请别用迅雷下载,失败请重下,重下不扣分!