开发者

Relocating items in a list

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜