为什么不字典都的AddRange? [英] Why doesn't Dictionary have AddRange?

查看:132
本文介绍了为什么不字典都的AddRange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题是基本够​​用,为什么不能我:

 词典<字符串,字符串> DIC =新字典<字符串,字符串>();
dic.AddRange(MethodThatReturnAnotherDic());
 

解决方案

范围并不真正具有任何意义的关联容器不是吗?我认为字典并将其存储在一个列表值,但不是唯一的哈希表。

总之,用C#可以编写合并词典你自己的扩展方法。

Title is basic enough, why can't I:

Dictionary<string, string> dic = new Dictionary<string, string>();
dic.AddRange(MethodThatReturnAnotherDic());

解决方案

Range doesn't really have any meaning to an associative container does it? I think Dictionary stores it's values in a sorted fashion, but that isn't unique to Hashtables.

Anyway, with C# you can write your own extension method to merge dictionaries.

这篇关于为什么不字典都的AddRange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆