是否有ObjectdCollection 1。是否与Objectd集合2合并?
想要组合两个ObjectIdCollments...只迭代每个对象并添加到第二个集合中的内容?假设我可以创建列表,但只是出于好奇而不是任何东西。谢谢!
**** Hidden Message ***** 嗨,没有用于组合/串联两个ObjectIdCollections的内置方法。就我而言,我避免使用ObjectIdCollection,除非AutoCAD API需要它。一般集合(List HashSet ...)更强大,也更灵活。您可以创建一个扩展方法来模拟列表,AddRange()方法: 公共静态类扩展。
{。
public static void add range(this objectid collection ids,objectid collection other ids)。
{。
foreach(other ids中的ObjectId id)id,添加(id);。
}。
}就我而言,我宁愿使用返回新IEnumerable的Linq扩展方法,以便原始集合保持不变。 公共静态类扩展。
{。
公共静态IEnumerableConcat(this ObjectId collection ids,IEnumerableother ids)。
{。
返回id,强制转换(),concat(other id);。
}。
。
public static IEnumerableConcat(this ObjectId collection ids,ObjectId collection other ids)。
{。
返回id,concat(other id,cast ());。
}。
}然后,如果需要,您可以轻松地将返回的IEnumerable转换为具体的集合: Listids3 = id S1。Concat(ids2),to list(); objectid collection id S4 = new objectid collection(id S1。Concat(ids2),ToArray());。
哇...谢谢你看起来超级有效率。 我认为您正在寻找的功能是“联合”——您希望组合ObjectIdCollections而不引入重复。
https://msdn . Microsoft . com/en-us/library/bb 341731(v = vs . 110)。aspx
ObjectIdCollection没有它,但是Linq有,所以您需要自己编写它。也许将集合分解成List ,Union that,然后重新构建ObjectIdCollection
另一种方法是将ObjectIdCollections转换成HashTables,然后组合它们。 Hi,如果您想删除重复项,您可以在上层Linq扩展方法中使用Union(正如CADbloke建议的那样)而不是Concat。公共静态IEnumableUnion(this ObjectIdCollection id, IEnumable其他人)=>。
ids.Cast(),联盟(其他);。
。
公共静态IEnumable联合(此ObjectIdCollection id, ObjectIdCollection其他ID)=>。
ids.Union(otherIds.Cast ());。
再次感谢
页:
[1]