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;
精彩评论