2

I need to convert the IEnumerable<string> emails to comma separated string. The iEnumerable is actually Hashset<string> with emails, I need to generate string with emails separated by ','

em1@hotmail.com, em2@gmail.com, em3@walla.com

how can I do it without using loop

Tim Schmelter
  • 429,027
  • 67
  • 649
  • 891
Yakov
  • 9,221
  • 29
  • 109
  • 199
  • possible duplicate of [Creating a comma separated list from IList or IEnumerable](http://stackoverflow.com/questions/799446/creating-a-comma-separated-list-from-iliststring-or-ienumerablestring) – Vincent van der Weele Dec 05 '14 at 17:57
  • No. I am not looking to create a list , but string – Yakov Dec 06 '14 at 06:47
  • did you even follow the link? The wording in the title might be a bit unfortunate but it is exactly the same question, with answers for C# 2.0, 3.5, and 4.0+ – Vincent van der Weele Dec 06 '14 at 10:58

1 Answers1

10

You can use String.Join:

string result = String.Join(", ", emails);
Tim Schmelter
  • 429,027
  • 67
  • 649
  • 891