KeyValuePair 和 Dictionary 的关系
1、KeyValuePair
a、KeyValuePair 是一个结构体(struct);
b、KeyValuePair 只包含一个Key、Value的键值对。
2、Dictionary
a、Dictionary 可以简单的看作是KeyValuePair 的集合;
b、Dictionary 可以包含多个Key、Value的键值对。
我们看一下KeyValuePair的源码
[源码]
再来看看Dictory的源码
[用法]
后端: 文件名 MarketCustomerService.cs, 下面dic就是一个Dictionary的结构,返回值 model.MarketCustomerList = dic
前端: index.cshtml
我们可以看到, Dictionary<TKey, TValue> 是 KeyValuePair<TKey, TValue>的集合