代码如下:

 string strs = "ad6la4ss42d6s3";
            Dictionary<char, int> dic = new Dictionary<char, int>();
            foreach(var item in strs)
            {
                if (dic.Keys.Contains(item))
                {
                    dic[item]++;
                }
                else
                {
                    dic.Add(item,1);
                }
            }
            foreach (var s in dic)
            {
                Console.WriteLine("字符:{0},出现次数为{1}",s.Key,s.Value);
            }

  用C#中的键值对遍历数组或字符串元素的次数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-12-28
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2021-06-30
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案