日期:2014-05-18 浏览次数:20823 次
static void MoveItem<T>(T[] arr, int from, int to) { int delta = from > to ? 1 : from < to ? -1 : 0; T moving = arr[from]; for (int i = to; i != from; i += delta) { T tmp = arr[i]; arr[i] = moving; moving = tmp; } arr[from] = moving; }
------解决方案--------------------
int lowIndex = targetIndex > newIndex ? newIndex: targetIndex;
int highIndex = targetIndex > newIndex ? targetIndex : newIndex;
string tmp = str[highIndex];
for(int i = highIndex; i > lowIndex; i--)
{
str[i] = str[i - 1];
}
str[lowIndex] = tmp;