开发者

Relocating items in a list

开发者 https://www.devze.com 2023-04-02 19:14 出处:网络
How can I make two items exchange their positions in a List<T>? For example, item 3 moves t开发者_StackOverflow中文版o position 1 and item 1 goes to position 3 in a list with five items. Thanks.

How can I make two items exchange their positions in a List<T>? For example, item 3 moves t开发者_StackOverflow中文版o position 1 and item 1 goes to position 3 in a list with five items. Thanks.


Just save one of the items in a variable before you overwrite it:

var temp = list[1];
list[1] = list[3];
list[3] = temp;
0

精彩评论

暂无评论...
验证码 换一张
取 消