Dictionary<Key,Value>的用法

简介: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.
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属性
目录
打赏
0
0
0
0
113
分享
相关文章
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
141 0
|
9月前
GEE错误:Dictionary does not contain key: bucketMeans.
GEE错误:Dictionary does not contain key: bucketMeans.
104 0
|
9月前
|
在Python中,字典(dictionary)的键(key)具有唯一标识性
在Python中,字典(dictionary)的键(key)具有唯一标识性
409 1
C# Dictionary通过value获取对应的key值[转发]
1:最直白的循环遍历方法,可以分为遍历key--value键值对以及所有的key两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq)  如下为一个十分简单的代码示例: private void GetDicKeyByValue() ...
1690 0
C#2.0泛型--Dictionary,List用法
泛型是 C#2.0 语言和公共语言运行库 (CLR) 中的一个新功能。泛型将类型参数的概念引入 .NET Framework,类型参数使得设计如下类和方法成为可能:这些类和方法将一个或多个类型的指定推迟到客户端代码声明并实例化该类或方法的时候。
796 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等