Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Основы.Практика
- {
- class Program
- {
- static void Main()
- {
- List<string> collection = new List<string>();
- string[] firstArray =
- {
- "2", "2", "2", "4", "5"
- };
- string[] secondArray =
- {
- "4", "4", "4", "2", "1"
- };
- Console.WriteLine("Перед сортировкой:");
- PrintArray(firstArray);
- PrintArray(secondArray);
- MergeUniqueArraysValuesIntoCollection(firstArray, secondArray, collection);
- Console.WriteLine("\nОбъеденная коллекция:");
- foreach (var item in collection)
- {
- Console.Write(item + " ");
- }
- }
- public static void PrintArray(string[] array)
- {
- foreach (var item in array)
- {
- Console.Write(item + " ");
- }
- Console.WriteLine();
- }
- public static void MergeUniqueArraysValuesIntoCollection(string[] array1, string[] array2, List<string> collection)
- {
- AddUniqueArrayValuesToCollection(array1, collection);
- AddUniqueArrayValuesToCollection(array2, collection);
- }
- public static void AddUniqueArrayValuesToCollection(string[] array, List<string> collection)
- {
- foreach (string item in array)
- {
- if (collection.Contains(item) == false)
- {
- collection.Add(item);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement