Advertisement
NikaBang

Объединение в одну коллекцию

Oct 28th, 2024 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. internal class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string[] numbers = { "1", "4", "6", "1", "2", "12", "9", "7" };
  9.         string[] numbers2 = { "3", "3", "2", "5", "8", "1", "4", "2" };
  10.  
  11.         List<string> combinedNumbers = new List<string>();
  12.  
  13.         AddNumbersToList(combinedNumbers, numbers);
  14.         AddNumbersToList(combinedNumbers, numbers2);
  15.  
  16.         foreach (string number in combinedNumbers)
  17.         {
  18.             Console.Write(number + " ");
  19.         }
  20.  
  21.         Console.ReadKey();
  22.     }
  23.  
  24.     static void AddNumbersToList(List<string> finalNumbers, string[] elementaryNumbers)
  25.     {
  26.         foreach (string number in elementaryNumbers)
  27.         {
  28.             if (finalNumbers.Contains(number) == false)
  29.             {
  30.                 finalNumbers.Add(number);
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement