HashSetset1 = new HashSet (){1, 2, 3}; HashSet set2 = new HashSet (){3, 4, 5}; set1.AddAll(set2); //set1 now contains {1, 2, 3, 4, 5}
HashSetThe HashSet AddAll method is part of the System.Collections.Generic namespace in C#, which is included in the .NET Framework package library.set1 = new HashSet (){"apple", "banana"}; string[] array = new string[]{"banana", "cherry", "date"}; set1.AddAll(array); //set1 now contains {"apple", "banana", "cherry", "date"}