Dr_Max_Experience

New task 10

Mar 20th, 2022 (edited)
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 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 HW
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string textFirst = "mauris rhoncus dictum lorem torquent per eu conubia nostra per inceptos himenaeos";
  14.             string textSecond = "class aptent taciti semper scelerisque eu mauris fermentum lacinia lorem";
  15.  
  16.             string[] wordsFirst = textFirst.Split(' ');
  17.             string[] wordsSecond = textSecond.Split(' ');
  18.  
  19.             Console.WriteLine(textFirst + " " + textSecond);
  20.  
  21.             List<string> newCollection = new List<string>();
  22.  
  23.             AddInCollection(newCollection, wordsFirst);
  24.             AddInCollection(newCollection, wordsSecond);
  25.  
  26.             ShowCollection(newCollection);
  27.             Console.ReadKey();
  28.         }
  29.  
  30.         static void AddInCollection(List<string> collection, string[] words)
  31.         {
  32.             for (int i = 0; i < words.Length; i++)
  33.             {
  34.                 if (AvailabilityInCollection(collection, words[i]) == false)
  35.                 {
  36.                     collection.Add(words[i]);
  37.                 }
  38.             }
  39.         }
  40.  
  41.         static void ShowCollection(List<string> collection)
  42.         {
  43.             foreach (var word in collection)
  44.             {
  45.                 Console.Write(word + " ");
  46.             }
  47.  
  48.             Console.WriteLine("\n\n");
  49.         }
  50.  
  51.         static bool AvailabilityInCollection(List<string> newCollection, string word)
  52.         {
  53.             foreach (var item in newCollection)
  54.             {
  55.                 if(item == word)
  56.                 {
  57.                     return true;
  58.                 }
  59.             }
  60.  
  61.             return false;
  62.         }
  63.     }
  64. }
Add Comment
Please, Sign In to add comment