C#: Union of two ICollections? (equivlaent of Java's addAll())
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-03-17T18:19:18Z
Indexed on
2010/03/17
18:21 UTC
Read the original article
Hit count: 201
I have two ICollection
s of which I would like to take the union. Currently, I'm doing this with a foreach loop, but that feels verbose and hideous. What is the C# equivalent of Java's addAll()
?
Example of this problem:
ICollection<IDictionary<string, string>> result = new HashSet<IDictionary<string, string>>();
// ...
ICollection<IDictionary<string, string>> fromSubTree = GetAllTypeWithin(elementName, element);
foreach (IDictionary<string, string> dict in fromSubTree) // hacky
{
result.Add(dict);
}
// result is now the union of the two sets
© Stack Overflow or respective owner