首页 > 编程知识 正文

【.net基础学习之】c#里 KeyValuePair和Dictory的区别

时间:2023-05-04 17:11:43 阅读:211897 作者:3477

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>的集合

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。