Reputation: 6817
I have a list of enum values:
public static readonly List<NotifyBy> SupportedNotificationMethods = new List<NotifyBy> {
NotifyBy.Email, NotifyBy.HandHold };
I would like to output it as a comma separated list. (EG: "Email, Handhold")
What is the cleanest way of doing this?
Upvotes: 8
Views: 10206
Reputation: 5132
you can use linq:
string.Join(", ", SupportedNotificationMethods.Select(e => e.ToString());
Upvotes: 4
Reputation: 141638
Perhaps this:
var str = String.Join(", ", SupportedNotificationMethods.Select(s => s.ToString()));
You can read more about the String.Join
method at MSDN. Older versions of String.Join
don't have an overload that takes an IEnumerable
. In that case just call ToArray()
after select.
Upvotes: 14
Reputation: 13141
String.Join(", ", SupportedNotificationMethods.Select(e => e.ToString()).ToArray());
Upvotes: 0