Tuesday, September 23, 2008

CommaDelimitedStringCollection class in .NET Framework

One simple but yet very interesting and useful class in .NET Framework that allows the creation of comma separated string from a list of string items is the CommaDelimitedStringCollection. This class is found in the System.Configuration namespace. So, we can stop reinventing the wheel each time we need such a collection, and instead, make use of this ready-made class.

Sample code...

CommaDelimitedStringCollection sites = new CommaDelimitedStringCollection();

sites.Add("www.yahoo.com");

sites.Add("www.google.com");

sites.AddRange(new string[] { "moiashvin-tech.blogspot.com", "www.lexpress.mu" });

Console.WriteLine(sites.ToString());


Output...
www.yahoo.com,www.google.com,moiashvin-tech.blogspot.com,www.lexpress.mu

No comments: