using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 计算字符 { class Program { static void Main(string[] args) { string str = "Welecome to China world"; Dictionary dict=new Dictionary(); foreach (char ch in str.ToLower()) { if (dict.ContainsKey(ch)) { dict[ch]++; } else { dict[ch] = 1; } } foreach (char cha in dict.Keys) { Console.WriteLine(cha.ToString()+"="+dict[cha]); } Console.ReadKey(); } } } 计算重复字符 用Dictionary,通过dictionary[key]就可以得到其Value值,如果要得到key可以用Dictionary.key属性