Advertisement
vovanhik_24

#37

Sep 10th, 2023 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             int[] firstArray = { 1, 2, 1, 6 };
  4.             int[] secondArray = { 3, 2, 4 };
  5.             List<int> listNumbers = new List<int>();
  6.  
  7.             MergingIntoOneCollection(listNumbers, firstArray);
  8.             MergingIntoOneCollection(listNumbers, secondArray);
  9.  
  10.             Console.Write("Список чисел без повторов: ");
  11.             ShowList(listNumbers);
  12.  
  13.             Console.WriteLine();
  14.         }
  15.        
  16.         private static void MergingIntoOneCollection(List<int> list, int[] array)
  17.         {
  18.             for (int i = 0; i < array.Length; i++)
  19.             {
  20.                 if (list.Contains(array[i]) != true)
  21.                 {
  22.                     list.Add(array[i]);
  23.                 }
  24.             }
  25.         }
  26.  
  27.         private static void ShowList(List<int> list)
  28.         {
  29.             foreach (int i in list)
  30.             {
  31.                 Console.Write(i + " ");
  32.             }
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement