Advertisement
Suslick

Untitled

Jan 28th, 2024 (edited)
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             int arrayLengthOne = 6;
  6.             int arrayLengthTwo = 4;
  7.  
  8.             string[] arrayNumberOne = new string[arrayLengthOne];
  9.             string[] arrayNumberTwo = new string[arrayLengthTwo];
  10.  
  11.             FillNumbers(arrayNumberOne);
  12.             FillNumbers(arrayNumberTwo);
  13.  
  14.             Print(arrayNumberOne);
  15.             Print(arrayNumberTwo);
  16.  
  17.             List<string> uniqueNumbers = new List<string>();
  18.  
  19.             JoinArray(uniqueNumbers, arrayNumberOne);
  20.             JoinArray(uniqueNumbers, arrayNumberTwo);
  21.  
  22.             Console.WriteLine(string.Join(" ", uniqueNumbers));
  23.  
  24.             Console.ReadKey();
  25.         }
  26.  
  27.         private static void FillNumbers(string[] array, int maxNumber = 6, int minNumber = 0)
  28.         {
  29.             Random random = new Random(DateTime.Now.Millisecond);
  30.             int randomNumber;
  31.  
  32.             for (int i = 0; i < array.Length; i++)
  33.             {
  34.                 randomNumber = random.Next(minNumber, maxNumber + 1);
  35.                 array[i] = randomNumber.ToString();
  36.             }
  37.         }
  38.  
  39.         private static void Print(string[] arrayNumber)
  40.         {
  41.             Console.WriteLine(String.Join(" ", arrayNumber));
  42.         }
  43.  
  44.         private static void JoinArray(List<string> uniqueNumbers, string[] array)
  45.         {
  46.             for (int i = 0; i < array.Length; i++)
  47.             {
  48.                 if (uniqueNumbers.Contains(array[i]) ==  false)
  49.                     uniqueNumbers.Add(array[i]);
  50.             }
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement