查找方式不区分大小写
使用了 Dictionary key不可重复的特性
string str1 = "C# Calculate The Number Of occurrences of all characters in the string";
str1 = str1.ToLower();
str1 = str1.Replace(" ", "");
Dictionary<char, int> dic = new Dictionary<char, int>();
for (int i = 0; i < str1.Length; i++)
{
if (dic.ContainsKey(str1[i]))
{
dic[str1[i]]++;
}
else
{
dic.Add(str1[i], 1);
}
}
foreach (KeyValuePair<char, int> item in dic)
{
Console.WriteLine($"{item.Key}出现了{item.Value}次");
}