使用列表,您可以执行以下操作:
list.AddRange(otherCollection);
HashSet
中没有add range方法。向HashSet
添加另一个ICollection
的最佳方法是什么
发布于 2013-03-07 17:17:51
这是一种方法:
public static class Extensions
{
public static bool AddRange<T>(this HashSet<T> source, IEnumerable<T> items)
{
bool allAdded = true;
foreach (T item in items)
{
allAdded &= source.Add(item);
}
return allAdded;
}
}
https://stackoverflow.com/questions/15267034
复制相似问题