Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Объединение_в_одну_коллекцию
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int minValue = 0;
- int maxValue = 3;
- int maxSizeArray = 10;
- int[] array1 = new int[maxSizeArray];
- int[] array2 = new int[maxSizeArray];
- List<int> collection = new List<int>();
- Random random = new Random();
- FillArray(array1, minValue,maxValue, random);
- Console.WriteLine("Первый массив:");
- DrawArray(array1);
- FillArray(array2, minValue,maxValue, random);
- Console.WriteLine();
- Console.WriteLine("Второй массив: ");
- DrawArray(array2);
- FillCollection(collection,array1);
- FillCollection(collection,array2);
- Console.WriteLine();
- Console.WriteLine("Результат: ");
- for (int i = 0; i < collection.Count; i++)
- {
- Console.Write(collection[i] + " ");
- }
- }
- static int[] FillArray(int[] array, int minValue, int maxValue, Random random)
- {
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minValue, maxValue);
- }
- return array;
- }
- static void DrawArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
- static void FillCollection(List<int> collection, int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (collection.Contains(array[i]) == false)
- {
- collection.Add(array[i]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement