- //Dictionary<K,V>示例代码
- public static void Main(string[] args){
- Dictionary<string, int> things = new Dictionary<string, int>();
- things.Add("Green Things", 29);
- things.Add("Blue Things", 94);
- things.Add("Yellow Things", 34);
- things.Add("Red Things", 52);
- things.Add("Brown Things", 27);
- foreach (KeyValuePair<string, int> item in things)//输出key-value
- {
- Console.WriteLine(item.Key + " :" + item.Value);
- }
- Console.WriteLine();
- foreach (string item in things.Keys)//输出key
- {
- Console.WriteLine(item);
- }
- Console.WriteLine();
- foreach (int item in things.Values)//输出value
- {
- Console.WriteLine(item);
- }
- Console.WriteLine();
- }
C#基础:泛型字典
最新推荐文章于 2023-06-15 17:15:46 发布