Add IndexMove() to List #110562
Replies: 3 comments 1 reply
-
For efficiency, you can use |
Beta Was this translation helpful? Give feedback.
-
Hm, a first step might be to invent for
where both methods return the detached list member as a shallow copy, or maybe as a reference (when reference type), instead of just deleting it like Remove()/RemoveAt() do. Then, in your case, the operation will shrink to
This might make the intention more clear. |
Beta Was this translation helpful? Give feedback.
-
I know it's not exactly what you are asking but you could always right it as an extension method [at least until C# adds this if they do] public static void IndexMove<T>(this List<T> list, int index, int newIndex) {
T element = list[index];
list.RemoveAt(index);
list.Insert(newIndex, element);
} but I do agree that this is a fairly major concept that is missing from lists in C# |
Beta Was this translation helpful? Give feedback.
-
The effect is similar to
This operation will cause all subsequent projects after the affected project to move meaningless twice.
I hope he has his own API to achieve this more efficiently.
Beta Was this translation helpful? Give feedback.
All reactions