Convert list <Enum> to list <string>

I have a list of enum values:

 public static readonly List<NotifyBy> SupportedNotificationMethods = new List<NotifyBy> { NotifyBy.Email, NotifyBy.HandHold }; 

I would like to display it as a comma separated list. (EG: "Email, Handhold")

What is the cleanest way to do this?

+7
source share
3 answers

Perhaps it:

 var str = String.Join(", ", SupportedNotificationMethods.Select(s => s.ToString())); 

You can learn more about the String.Join method on MSDN . Older versions of String.Join do not have an overload that accepts IEnumerable . In this case, just call ToArray() after the selection.

+12
source

you can use linq:

 string.Join(", ", SupportedNotificationMethods.Select(e => e.ToString()); 
+4
source
 String.Join(", ", SupportedNotificationMethods.Select(e => e.ToString()).ToArray()); 
0
source

All Articles