fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ABC
  7. {
  8. static class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<int> L = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
  13.  
  14. List<int> L2 = L.Swap(0, 9).ShowConsole().ToList();
  15.  
  16. return;
  17. }
  18.  
  19. public static IEnumerable<T> Swap<T>(this IEnumerable<T> Collection, int IdxA, int IdxB)
  20. {
  21. for (int i = 0; i < Collection.Count(); i++)
  22. {
  23. if (i == IdxA)
  24. {
  25. yield return Collection.ElementAt(IdxB);
  26. continue;
  27. }
  28. if (i == IdxB)
  29. {
  30. yield return Collection.ElementAt(IdxA);
  31. continue;
  32. }
  33. yield return Collection.ElementAt(i);
  34. }
  35. }
  36. public static IEnumerable<T> ShowConsole<T>(this IEnumerable<T> Collection)
  37. {
  38.  
  39. foreach (var o in Collection)
  40. {
  41. Console.WriteLine(o);
  42. }
  43.  
  44. return Collection;
  45. }
  46. }
  47. }
Success #stdin #stdout 0.03s 37072KB
stdin
Standard input is empty
stdout
9
1
2
3
4
5
6
7
8
0