Create a comma-delimited list from IEnumerable


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. string result = string.Empty;
  2.  
  3. List<int> listOfInts = new List<int>();
  4. foreach (int number in listOfInts)
  5. {
  6. if (number == listOfInts.Last())
  7. {
  8. result += number;
  9. }
  10. else
  11. {
  12. result += string.format("{0},", number);
  13. }
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.