Posted By

kwhite1975 on 04/03/13


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danfinrud55


Create Comma Separated List


 / Published in: C#
 

This simple code creates a comma separated list. The beauty of this code is that most times you have to check for the last item and do something different or cut off the last character to make the list work well. This does all of that in a single line.

  1. for (int i = 0; i < tbl.Rows.Count; i++)
  2. {
  3. DataRow dr = tbl.Rows[i];
  4. someString += dr["someValue"] + (i+1 == tbl.Rows.Count ? "" : ",");
  5. }

Report this snippet  

You need to login to post a comment.