Advertisement
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 = ReadStringArray(' ');
- string[] secondArray = ReadStringArray(' ');
- HashSet<string> unionCollection = new HashSet<string>();
- AddRangeToCollection(unionCollection, firstArray);
- AddRangeToCollection(unionCollection, secondArray);
- Console.WriteLine("Итоговая коллекция: ");
- PrintCollection(unionCollection);
- }
- private static void AddRangeToCollection<T>(ICollection<T> originCollection, IList<T> addedCollection)
- {
- foreach (T addedElement in addedCollection)
- {
- originCollection.Add(addedElement);
- }
- }
- private static void PrintCollection<T>(ICollection<T> collection)
- {
- foreach (T element in collection)
- {
- Console.Write($"{element} ");
- }
- Console.WriteLine();
- }
- private static string[] ReadStringArray(char separator)
- {
- Console.WriteLine($"Введите массив через '{separator}'");
- string text = Console.ReadLine();
- string[] result = text.Split(separator);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement