What Was I Thinking?

Follies & Foils of .NET Development
posts - 95 , comments - 352 , trackbacks - 0

My Links



Post Categories

Check These Out


December 2008 Entries

QuickTip - Flatten strings to a comma delimited list
Ever need to convert a List of strings in a comma delimited list? In the past I'd write a foreach loop. Something like: public static string FlattenStringList(List<s... items) { StringBuilder str = new StringBuilder(); bool firstOne = false; foreach (string item in items) { if (!firstOne) str.Append(","); else firstOne = false; str.Append(item); } return str.ToString(); } Now, thanks to String.Join and Linq, I can compress it to a single expression: string.Join(",", items.ToArray()); Also ......

Posted On Tuesday, December 23, 2008 1:03 AM | Comments (0) | Filed Under [ Visual Studio ]

Powered by: