C#
C#: List Swap (by index)
개태형님
2021. 1. 30. 16:40
List에 index로 서로의 위치를 변경하고자 할때 쓰인다.
ex) Drag&Move로 아이템의 위치를 변경하고자 할때
C#에서 제공하는 함수는 없으며, 확장 메서드로 따로 구현 하여야 한다.
public static class ExtensionList
{
public static void Swap<T>(this List<T> list, int from, int to)
{
T tmp = list[from];
list[from] = list[to];
list[to] = tmp;
}
}