C# KeyValuePair<TKey,TValue> 与 Dictionary<TKey,TValue> 区别
时间:2020-08-28 00:14:23
收藏:0
阅读:422
KeyValuePair<TKey,TValue>
- 可以设置、查询的一对键值 是struct
Dictionary<TKey,TValue>
- 可以设置、查询的多对键值的集合
总结
- KeyValuePair是Dictionary集合元素类型的对象
foreach( KeyValuePair<string, string> kvp in myDictionary )
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
- 可以通过List<KeyValuePair<TKey,TValue>>创建KeyValuePair的集合 当list中所有KeyValuePair的Tkey不重复时 可以与Dictionary<TKey,TValue>进行转换
原文:https://www.cnblogs.com/Alicia-meng/p/13574845.html
评论(0)