C# HashSet to single string

You will loop over the contents, whether you explicitly write one or not.

However, to do it without the explicit writing, and if by “cast” you mean “concatenate”, you would write something like this

string output = string.Join("", yourSet); // .NET 4.0
string output = string.Join("", yourSet.ToArray()); // .NET 3.5

Leave a Comment