Teo_Yanchev

ListsExercise - 2.ChangeList - C# Fundamentals

Sep 19th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Security.Cryptography.X509Certificates;
  6.  
  7. namespace _2.ChangeList
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. List<int> numbers = Console.ReadLine()
  14. .Split()
  15. .Select(int.Parse)
  16. .ToList();
  17.  
  18. List<string> command = Console.ReadLine()
  19. .Split()
  20. .ToList();
  21. while (command[0] != "end")
  22. {
  23. string firstCommand = command[0];
  24. if (firstCommand == "Delete")
  25. {
  26. // int x = int.Parse(command[1]);
  27. // numbers.RemoveAt(0);
  28. numbers.RemoveAll(x => x == int.Parse(command[1]));
  29.  
  30. command = Console.ReadLine()
  31. .Split()
  32. .ToList();
  33. continue;
  34. }
  35.  
  36. else if (firstCommand == "Insert")
  37. {
  38. int index = int.Parse(command[1]);
  39. int number = int.Parse(command[2]);
  40. numbers.Insert(number, index);
  41.  
  42. command = Console.ReadLine()
  43. .Split()
  44. .ToList();
  45. continue;
  46. }
  47. }
  48.  
  49. Console.WriteLine(string.Join(" ", numbers));
  50. }
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment