Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat HashSet<String> and IList<String>

Tags:

c#

I have a hash set as :

HashSet<String> hash ;

and a list as:

IList<String> names = new List<String>(){"ABC","DEF"};

I want to concat hash and names; then store the result in same variable i.e. hash.

What is the best approach to do this since I have arround 10k records to store in HashSet?

like image 927
M.S. Avatar asked Mar 13 '14 09:03

M.S.


1 Answers

Use UnionWith:

Modifies the current HashSet object to contain all elements that are present in itself, the specified collection, or both.

hash.UnionWith(names);
like image 107
sloth Avatar answered Nov 10 '22 01:11

sloth