LINQ经典面试案列
作者:互联网
题目:统计一个字符串中每个字母出现的频率(忽然大小写),然后按照从高到低输出频率高于2次的单词和出现的频率。
代码:
string strabc = "hello chenchen is me,are you ok?"; var items=strabc.Where(c => char.IsLetter(c)).Select(c => char.ToLower(c)).GroupBy(c => c).Select(g => new { g.Key, Count = g.Count() }).OrderByDescending (g => g.Count).Where(g => g.Count > 2); foreach(var item in items) { Console.WriteLine(item); }
标签:Count,item,案列,LINQ,strabc,char,面试,var,Where 来源: https://www.cnblogs.com/NangFah/p/16636505.html