How do I convert a HashSet<T> to an array in .NET?
Use the HashSet<T>.CopyTo
method. This method copies the items from the HashSet<T>
to an array.
So given a HashSet<String>
called stringSet
you would do something like this:
String[] stringArray = new String[stringSet.Count];
stringSet.CopyTo(stringArray);