desislava_topuzakova

3. Списък с имена

Mar 13th, 2022
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3._List_of_Names
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.            
  12.             string input = Console.ReadLine(); //"Ivan Maria Dimitar Simona Petya"
  13.             List<string> names = input.Split(" ") // масив: ["Ivan", "Maria", "Dimitar", "Simona", "Petya"]
  14.                                 .ToList(); // лист: {"Ivan", "Maria", "Dimitar", "Simona", "Petya"}
  15.  
  16.             //обходя всички елементи в списъка names -> отпечатвам + ;
  17.             //1. for - index
  18.             /*for (int index = 0; index <= names.Count - 1; index++)
  19.             {
  20.                 Console.WriteLine(names[index] + "; ");
  21.             }*/
  22.  
  23.             //2. foreach - element
  24.             /*foreach (string name in names)
  25.             {
  26.                 Console.Write(name + "; ");
  27.             }*/
  28.  
  29.             Console.WriteLine(String.Join(';', names));
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment