1   static void Main(string[] args)
 2   {
 3             string ss = "12345678904682qwertyuioplkjhgfdsazxcvbnmmlpokuhygtfcdgtrf";
 4             char[] a = ss.ToCharArray();
 5             var q = from p in ss group p by p into g select g;// new { g, count=g.Count()};
 6             foreach (var item in q)
 7             {
 8                 Console.WriteLine(item.Key + " 出现了 " + item.Count() + "");
 9             }
10             Console.ReadKey();
11   }

以上是在C# 编写。结合网上各种代码。这个问题在面试中出现的频率比较大。

效果图如下。