Merge Hashset object and List object in C#

The following example demonstrates the use of the UnionWith method for merging a HashSet object and List object. Suppose objHash and objList are hashset and list objects of the int type respectively then you can merge objHash object to the objList like as:
 

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Merge Hashset<t> object and List<t> object in C#
 
            HashSet<int> objHash = new HashSet<int>();
            List<int> objList = new List<int>();
 
            objHash.Add(11);
            objHash.Add(12);
            objHash.Add(13);
 
            objList.Add(14);
            objList.Add(15);
            objList.Add(16);
 
            objHash.UnionWith(objList);
 
            Console.WriteLine("Total count of the EmployeeIds= "
      + objHash.Count);
            foreach (int i in objHash)
            {
                Console.WriteLine(i);
            }
            Console.ReadKey();
        }
    }
}

 
The output of the above program will be:
Total count of the EmployeeIds=6
11
12
13
14
15
16