KeyValuePair 和 Dictionary 的关系
时间:2023-05-04 12:07:09 阅读:211910 作者:609
KeyValuePair 和 Dictionary 的关系 1、KeyValuePair a、KeyValuePair 是一个结构体(struct); b、KeyValuePair 只包含一个Key、Value的键值对。 2、Dictionary a、Dictionary 可以简单的看作是KeyValuePair 的集合; b、Dictionary 可以包含多个Key、Value的键值对。
下面的代码可能会帮助更好的理解它们之间的关系: [csharp] view plain copy Dictionary<int, string> myDic = new Dictionary<int, string>(); foreach (KeyValuePair<int, string> item in myDic) { Console.WriteLine("Key = {0}, Value = {1}", item.Key, item.Value); }
版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。