Hi,
There is no built-in method for combining / concatenating two ObjectIdCollections.
For my part, I avoid using ObjectIdCollection except when the AutoCAD API requires it.
Generic collections (List <Objectid>, HashSet <ObjectId>, ...) are more powerful and more flexible.
You can create an extension method to mimic the List<T>.AddRange() method:
public static class Extension
{
public static void AddRange(this ObjectIdCollection ids, ObjectIdCollection otherIds)
{
foreach (ObjectId id in otherIds) ids.Add(id);
}
}
By my side, I'd rather use Linq extension methods which return a new IEnumerable<ObjectId> so that the original collections remain unchanged.
public static class Extension
{
public static IEnumerable<ObjectId> Concat(this ObjectIdCollection ids, IEnumerable<ObjectId> otherIds)
{
return ids.Cast<ObjectId>().Concat(otherIds);
}
public static IEnumerable<ObjectId> Concat(this ObjectIdCollection ids, ObjectIdCollection otherIds)
{
return ids.Concat(otherIds.Cast<ObjectId>());
}
}
Then, if needed, you can easily convert the returned IEnumerable<objectId> into a concrete collection:
List<ObjectId> ids3 = ids1.Concat(ids2).ToList();
ObjectIdCollection ids4
= new ObjectIdCollection
(ids1
.Concat(ids2
).ToArray());