Advertisement
SaNik74

Add in one collection

Apr 11th, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. namespace Add_in_one_collection
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             List<string> list = new List<string>();
  8.             string[] numbersInFirstString = { "2", "4", "6", "9", "1" };
  9.             string[] numbersInSecondString = { "3", "2", "8", "4", "6", "9" };
  10.             AddAllUniqueValuesInList(list, numbersInFirstString, numbersInSecondString);
  11.  
  12.             foreach (string value in list)
  13.             {
  14.                 Console.Write(value + " ");
  15.             }
  16.         }
  17.  
  18.         static void AddUniqueValuesInList(List<string> list, string[] array)
  19.         {
  20.             foreach (string value in array)
  21.             {
  22.                 if (!list.Contains(value))
  23.  
  24.                 {
  25.                     list.Add(value);
  26.                 }
  27.             }
  28.         }
  29.  
  30.         static void AddAllUniqueValuesInList(List<string> list, string[] array1, string[] array2)
  31.         {
  32.             AddUniqueValuesInList(list, array1);
  33.             AddUniqueValuesInList(list, array2);
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement