是否有一个等价的AddRange在C#中HashSet的 [英] Is there an AddRange equivalent for a HashSet in C#
问题描述
通过列表,你可以这样做:
With a list you can do:
list.AddRange(otherCollection);
有是在 HashSet的无添加范围的方法。
什么是另一个集合添加到HashSet的最佳方式?
There is no add range method in a HashSet. What is the best way to add another collection to a HashSet?
推荐答案
有关HashSet的,名字是<一个HREF =http://msdn.microsoft.com/en-us/library/bb342097.aspx> UnionWith 。
For HashSet, the name is UnionWith.
这是指示不同的方式HashSet的工作。你不能安全地增加设置随机元素把它像集合,某些元素可能自然蒸发的。
This is to indicate the distinct way the HashSet works. You cannot safely "Add" set of random elements to it like in Collections, some elements may naturally evaporate.
我觉得UnionWith与另一HashSet的合并而得名,然而,有一个为IEnumerable的过载过:)
I think that UnionWith takes its name after "merging with another HashSet", however, there's an overload for IEnumerable too :)
这篇关于是否有一个等价的AddRange在C#中HashSet的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!