This post will discuss how to swap two items in a List in C#.

We can easily write an extension method to swap an element of the list with another element. For example, consider the following code, which swaps the element at index 2 with the element at index 3 in the list using a temporary variable.

Download  Run Code

 
Note that the extension method needs to go inside a static class. Alternatively, you can simply write:

Download  Run Code

That’s all about swapping two items in a List in C#.