我正在寻找更好的数据结构或方法来简单替换动态数组中的对象。似乎列表是选择,但是我阅读并注意到RemoveAt和Insert的性能不如我所希望的那么好。替代RemoveAt并插入列表项目
让我解释什么,我想实现:
列表1
- 清单项目1
- 列表项2
- 列表项3
列表2
- 列表项1
- 列表项2
- 空
两个列表使用相同的对象类型。我想用List1 [1] - List item 1 clone来替换List2的空列表项。我使用克隆,因此复制的列表项的值是一个单独的实例。
我也想用列表2的列表项1的克隆替换列表2的列表项2。
这里是什么,我想实现一些示例代码:
projCraneVertices.RemoveAt(projCraneVertices.Count - 4);
projCraneVertices.Insert((projCraneVertices.Count - 3), realCraneVertices[botPoint].clone());
projCraneVertices.RemoveAt(projCraneVertices.Count - 3);
projCraneVertices.Insert((projCraneVertices.Count - 2), projCraneVertices[botPoint].clone());
projCraneVertices.RemoveAt(projCraneVertices.Count - 2);
projCraneVertices.Insert((projCraneVertices.Count - 1), realCraneVertices[topPoint].clone());
projCraneVertices.RemoveAt(projCraneVertices.Count - 1);
projCraneVertices.Insert((projCraneVertices.Count), projCraneVertices[topPoint].clone());
我想应该是这样简单。我在没有克隆功能的情况下尝试过类似于此的操作,但它不能按预期工作。谢谢。 – 2013-03-18 14:33:18