Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. int numberOfLines = int.Parse(Console.ReadLine());
  2. List<Box<int>> boxCollection = new List<Box<int>>();
  3.  
  4. for (int i = 0; i < numberOfLines; i++)
  5. {
  6. Box<int> boxInt = new Box<int>(int.Parse(Console.ReadLine()));
  7. boxCollection.Add(boxInt);
  8. }
  9.  
  10. var indexes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.  
  12. SwapElements(boxCollection, indexes[0], indexes[1]);
  13.  
  14. foreach (var box in boxCollection)
  15. {
  16. Console.WriteLine(box);
  17. }
  18. }
  19.  
  20. private static void SwapElements<T>(List<T> boxCollection, int index1, int index2)
  21. {
  22. T tempBox = boxCollection[index1];
  23. boxCollection[index1] = boxCollection[index2];
  24. boxCollection[2] = tempBox;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement