Advertisement
holllowknight

Объединение

Apr 13th, 2023
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace array
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] stringSet1 = { "1", "2", "1" };
  11.             string[] stringSet2 = { "4", "3", "2" };
  12.             List<string> combinedCollection = new List<string>();
  13.  
  14.             AddSingleRecords(stringSet1, combinedCollection);
  15.             AddSingleRecords(stringSet2, combinedCollection);
  16.             ShowList(combinedCollection);
  17.         }
  18.  
  19.         private static void AddSingleRecords(string[] stringSet, List<string> singlesList)
  20.         {
  21.             foreach (string element in stringSet)
  22.                 if (singlesList.Contains(element) == false)
  23.                     singlesList.Add(element);
  24.         }
  25.  
  26.         private static void ShowList(List<string> collection)
  27.         {
  28.             foreach (string element in collection)
  29.                 Console.Write($"{element} ");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement