RedFlys

Home work - merging in one collection

Mar 21st, 2022
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home_Work
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             string[] source1 = { "Мама", "Папа", "Сын", "Дочь" };
  14.             string[] source2 = { "Бабушка", "Дедушка", "Мама", "Папа" };
  15.             List<string> words = new List<string>();
  16.  
  17.             FillListFromArray(words, source1);
  18.             FillListFromArray(words, source2);
  19.  
  20.             ShowWords(words);
  21.         }
  22.  
  23.         static void FillListFromArray(List<string> words, string[] source)
  24.         {
  25.             foreach (string word in source)
  26.             {
  27.                 if (words.Contains(word) == false)
  28.                 {
  29.                     words.Add(word);
  30.                 }
  31.             }
  32.         }
  33.  
  34.         static void ShowWords(List<string> words)
  35.         {
  36.             foreach(string word in words)
  37.             {
  38.                 Console.Write(word + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment