Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] firstArray = InputStringArray(' ');
- string[] secondArray = InputStringArray(' ');
- List<string> result = UnionArrays(firstArray, secondArray);
- Console.WriteLine("Итоговая коллекция: ");
- PrintCollection(result);
- }
- private static void PrintCollection<T>(IList<T> collection)
- {
- foreach (T element in collection)
- {
- Console.Write($"{element} ");
- }
- Console.WriteLine();
- }
- private static List<T> UnionArrays<T>(IList<T> firstCollection, IList<T> secondCollection)
- {
- List<T> unionCollection = new List<T>(firstCollection);
- unionCollection.AddRange(secondCollection);
- return Distinct(unionCollection);
- }
- private static List<T> Distinct<T>(IList<T> collection)
- {
- List<T> distinctCollection = new List<T>();
- foreach (T element in collection)
- {
- if(distinctCollection.Contains(element) == false)
- distinctCollection.Add(element);
- }
- return distinctCollection;
- }
- private static string[] InputStringArray(char separator)
- {
- Console.WriteLine($"Введите массив через '{separator}'");
- string text = Console.ReadLine();
- string[] result = text.Split(separator);
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment