Friday 24 November 2017

collections - Is there an AddRange equivalent for a HashSet in C#

itemprop="text">

With a list you can
do:



list.AddRange(otherCollection);



There
is no add range method in a HashSet.
What is the
best way to add another collection to a HashSet?



Answer




For
HashSet, the name is href="http://msdn.microsoft.com/en-us/library/bb342097.aspx"
rel="noreferrer">UnionWith.



This
is to indicate the distinct way the HashSet works. You cannot
safely Add a set of random elements to it like in
Collections, some elements may naturally
evaporate.



I think that
UnionWith takes its name after "merging with another
HashSet", however, there's an overload for
IEnumerable too.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...