TwinFrame

CombineArraysToCollection

Mar 20th, 2022 (edited)
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Clight_54_CombineArraysToCollection
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] firstTexts = new string[] { "Четвертая строка", "Первая строка", "Первая строка", "Вторая строка", "Третья строка", "Вторая строка" };
  11.             string[] secondTexts = new string[] { "Четвертая строка", "Вторая строка", "Пятая строка", "Вторая строка" };
  12.  
  13.             List<string> combineTexts = new List<string>();
  14.  
  15.             AddTextsToList(firstTexts, combineTexts);
  16.             AddTextsToList(secondTexts, combineTexts);
  17.  
  18.             foreach (var text in combineTexts)
  19.                 Console.WriteLine(text);
  20.  
  21.             Console.ReadKey();
  22.         }
  23.  
  24.         public static void AddTextsToList(string[] addTexts, List<string> combineTexts)
  25.         {
  26.             for (int i = 0; i < addTexts.Length; i++)
  27.             {
  28.                 if(combineTexts.Contains(addTexts[i]) == false)
  29.                     combineTexts.Add(addTexts[i]);
  30.             }
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment