Answer to Question #269364 in C# for Bully

Question #269364

Write a program that involving 2 hash sets populate with 5 members coming from the user. Perform the set operation (UNION, INTERSECTION)


1
Expert's answer
2021-11-21T04:57:37-0500
 internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Input values for first hash set: ");
            Input(out HashSet<int> firstHashSet);
            Console.WriteLine("Input values for second hash set: ");
            Input(out HashSet<int> secondHashSet);
            Console.WriteLine($"UNION result: {string.Join(" ", firstHashSet.Union(secondHashSet).ToArray())}");
            Console.WriteLine($"INTERSECTION result: {string.Join(" ", firstHashSet.Intersect(secondHashSet).ToArray())}");


            Console.ReadLine();
        }
        public static void Input(out HashSet<int> collection)
        {
            collection = new HashSet<int>();
            for (int i = 0; i < 5; i++)
            {
                Console.Write($"{i + 1}. = ");
                collection.Add(int.Parse(Console.ReadLine()));
            }
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS