Dictionary<,>
using System;
using System.Collections.Generic;
namespace _076_字典集合
{
class Program
{
static void Main(string[] args)
{
//Dictionary<TKey,TValue> 指定类型的键、值
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1, "卡特琳娜");
dic.Add(2, "阿卡丽");
dic.Add(3, "瑞雯");
//dic.Add(1, "会异常");
//dic[1] = "不会异常";
foreach (var item in dic)
{
Console.WriteLine(item);
}
Console.WriteLine("=========================================");
foreach (KeyValuePair<int, string> kv in dic)
{
Console.WriteLine("键:{0},值:{1}", kv.Key, kv.Value);
}
Console.WriteLine("=========================================");
foreach (var item in dic.Keys)
{
Console.WriteLine("键:{0},值:{1}", item, dic[item]);
}
Console.WriteLine("=========================================");
Console.ReadKey();
}
}
}