【C#】字典集合Dictionary
原创
©著作权归作者所有:来自51CTO博客作者深漂小码哥的原创作品,请联系作者获取转载授权,否则将追究法律责任
代码示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1, "张三");
dic.Add(2, "李四");
dic.Add(3, "王五");
foreach (var item in dic.Keys)
{
Console.WriteLine("{0}---{1}", item, dic[item]);
}
foreach (KeyValuePair<int, string> kv in dic)
{
Console.WriteLine("{0}---{1}", kv.Key, kv.Value);
}
}
}
}
执行结果