C#: Union of two ICollections? (equivlaent of Java's addAll())
- by Rosarch
I have two ICollections 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