gpt4 book ai didi

c# - 将 List 转换为 List

转载 作者:太空狗 更新时间:2023-10-29 18:12:29 25 4
gpt4 key购买 nike

我有一个枚举值列表:

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

我想将其输出为逗号分隔列表。 (例如:“电子邮件,掌上电脑”)

最干净的方法是什么?

最佳答案

也许是这样:

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

您可以在 MSDN 阅读有关 String.Join 方法的更多信息. String.Join 的旧版本没有采用 IEnumerable 的重载。在这种情况下,只需在选择后调用 ToArray()

关于c# - 将 List<Enum> 转换为 List<string>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8157327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com