Advertisement
desislava_topuzakova

2. Въвеждане на списък от конзолата чрез 1 ред

Mar 18th, 2023
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._InputList
  6. {
  7. internal class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = Console.ReadLine(); //"1 2 3 4 5 6"
  12.  
  13. List<int> numbers = input.Split(" ") // ["1", "2", "3", "4", "5", "6"]
  14. .Select(int.Parse) // [1, 2, 3, 4, 5, 6]
  15. .ToList(); // {1, 2, 3, 4, 5, 6}
  16.  
  17. for (int index = 0; index <= numbers.Count - 1; index++)
  18. {
  19. Console.WriteLine("nums[" + index + "] = " + numbers[index]);
  20. }
  21. }
  22. }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement