Advertisement
Rodunskiy

Untitled

May 12th, 2025
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. namespace CSLight
  2. {
  3.     public class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             int[] arrayOne = new int[5] {1,2,3,3,5};
  8.             int[] arrayTwo = new int[4] {3,5,5,4};
  9.  
  10.             List<int> numbers = new List<int>();
  11.  
  12.             AddToCollectionWithoutDuplicates(arrayOne, numbers);
  13.             AddToCollectionWithoutDuplicates(arrayTwo, numbers);
  14.  
  15.             Console.WriteLine("Результат объединения без повторений:");
  16.  
  17.             foreach (var number in numbers)
  18.             {
  19.                 Console.Write(number + " ");
  20.             }
  21.         }
  22.  
  23.         static void AddToCollectionWithoutDuplicates(int[] array, List<int> list)
  24.         {
  25.             for (int i = 0; i < array.Length; i++)
  26.             {
  27.                 if (!list.Contains(array[i]))
  28.                 {
  29.                     list.Add(array[i]);
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement