
string str1 = "ConsoleReadLine";
//计算字符串里面的字符各出现了多少次
Dictionary<char, int> dic = new Dictionary<char, int>();//声明了一个字典类型,键为字符,值为数字
for (int i = 0; i < str1.Length; i++)
{
if (dic.ContainsKey(str1[i]))//判断键是否重复
{
dic[str1[i]]+=1;
}
else
{
dic[str1[i]] = 1;
}
}
foreach (var item in dic)
{
Console.WriteLine("{0}----------{1}", item.Key, item.Value);
}
Console.ReadKey();