KeyValuePair 和 Dictionary 的关系

KeyValuePair 和 Dictionary 的关系
1、KeyValuePair 
    a、KeyValuePair 是一个结构体(struct);
    b、KeyValuePair 只包含一个Key、Value的键值对。
2、Dictionary 
    a、Dictionary 可以简单的看作是KeyValuePair 的集合;
    b、Dictionary 可以包含多个Key、Value的键值对。
1 Dictionary<int, string> myDic = new Dictionary<int, string>();
2 foreach (KeyValuePair<int, string> item in myDic)
3 {
4     Console.WriteLine("Key = {0}, Value = {1}", item.Key, item.Value);
5 }

转载于 https://blog.csdn.net/aphy358/article/details/50039099

posted @ 2020-11-28 16:49  小夏先生  阅读(129)  评论(0编辑  收藏  举报