using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC { static class Program { static void Main(string[] args) { List L = new List() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, }; List L2 = L.Swap(0, 9).ShowConsole().ToList(); return; } public static IEnumerable Swap(this IEnumerable Collection, int IdxA, int IdxB) { for (int i = 0; i < Collection.Count(); i++) { if (i == IdxA) { yield return Collection.ElementAt(IdxB); continue; } if (i == IdxB) { yield return Collection.ElementAt(IdxA); continue; } yield return Collection.ElementAt(i); } } public static IEnumerable ShowConsole(this IEnumerable Collection) { foreach (var o in Collection) { Console.WriteLine(o); } return Collection; } } }