Shallow copy of a hashset
问题 Whats the best way of doing it? var set2 = new HashSet<reference_type>(); Traverse the set with a foreach like this. foreach (var n in set) set2.Add(n); Or use something like union like this. set2 = set.UnionWith(set); // all the elements 回答1: Use the constructor: HashSet<type> set2 = new HashSet<type>(set1); Personally I wish LINQ to Objects had a ToHashSet extension method as it does for List and Dictionary . It's easy to create your own of course: public static HashSet<T> ToHashSet<T>(this