代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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); } |