A personal repository of technical notes. - CSC

HashSet to Comma Delimited String

HashSet Coding Example: A HashSet is a collection that contains no duplicate elements.

Note: Tested in .NET 4.0.

       HashSet<string> myHashSet = new HashSet<string>();
       myHashSet.Add("A");
       myHashSet.Add("B");
       myHashSet.Add("B");
       myHashSet.Add("B");
       myHashSet.Add("B");
       myHashSet.Add("X");
       myHashSet.Add("Z");
       myHashSet.Add("B");
       myHashSet.Add("A");
       string commaDelimitedString = String.Join<string>(",", myHashSet);
       // commaDelimitedString is equal to "A,B,X,Z"

References
"HashSet(T) Class (System.Collections.Generic)." MSDN – the Microsoft Developer Network. N.p., n.d. Web. 16 Oct. 2013. <http://msdn.microsoft.com/en-us/library/bb359438(v=vs.100).aspx>.

No comments:

Post a Comment