What Was I Thinking?

Follies & Foils of .NET Development

  Home  |   Contact  |   Syndication    |   Login
  74 Posts | 0 Stories | 191 Comments | 0 Trackbacks

News

Archives

Post Categories

Check These Out

Gurus

December 2008 Entries

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati