有一个对象是一个数组(不是arraylist或泛型),可以容纳一组任何东西......
[[One],[Two],[Three],[Four]]
想要将[Four]移动到[Two]前面,例如oldIndex = 3,newIndex = 1,那么结果将是......
[[One],[Four][Two],[Three]]
什么是在.NET 2.0中最有效的方法,例如
PropertyInfo oPI = ObjectType.GetProperty("MyArray", BindingFlags.Public | BindingFlags.Instance); object ObjectToReorder = oPI.GetValue(ParentObject, null); Array arr = ObjectToReorder as Array; int oldIndex = 3; int newIndex = 1; //Need the re-ordered list still attached to the ParentObject
提前致谢
void MoveWithinArray(Array array, int source, int dest) { Object temp = array.GetValue(source); Array.Copy(array, dest, array, dest + 1, source - dest); array.SetValue(temp, dest); }