Advertisement
SPavelA

Unite Arrays

Sep 25th, 2024 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CollectionsTask5UniteArrays
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] worlds1 = { "aaa", "bbb", "ccc", "ddd", "bbb", "yyy" };
  11.             string[] worlds2 = { "ggg", "ee", "dgfd", "bbb", "aaa", "xxx" };
  12.             List<string> allWorlds = new List<string>();
  13.  
  14.             AddArrayToList(worlds1, allWorlds);
  15.             AddArrayToList(worlds2, allWorlds);
  16.  
  17.             foreach (string item in allWorlds)
  18.             {
  19.                 Console.WriteLine(item + " ");
  20.             }
  21.  
  22.             Console.ReadKey();
  23.         }
  24.  
  25.         private static void AddArrayToList(string[] array, List<string> list)
  26.         {
  27.             foreach (string item in array)
  28.             {
  29.                 if(list.Contains(item) == false)
  30.                 {
  31.                     list.Add(item);
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement