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 }
View Code

 


原文链接:https://blog.csdn.net/nodeman/article/details/80810376

posted @ 2022-03-24 16:15  新宇笑  阅读(275)  评论(0)    收藏  举报