Convert IEnumerable list to comma separated string

If you want to create a comma seperated list of an IEnumerable source, first of all you have to convert the list to an List<T>. Then you could use String.Join to create the string.

This example shows the converting of CheckedItems of the CheckedListBox Control:

var myCommaString = String.Join(",", checkedListBox1.CheckedItems.OfType().ToList().Select(x => x.ToString()).ToArray());
This entry was posted in C#, Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s