c# - 如何将 IEnumerable<string> 转换为一个逗号分隔的字符串?

标签 c# string linq collections ienumerable

假设出于调试目的,我想快速将 IEnumerable 的内容放入单行字符串中,每个字符串项以逗号分隔。我可以在带有 foreach 循环的辅助方法中完成它,但这既不有趣也不简短。可以使用Linq吗?其他一些简短的方法?

最佳答案

using System;
using System.Collections.Generic;
using System.Linq;

class C
{
    public static void Main()
    {
        var a = new []{
            "First", "Second", "Third"
        };

        System.Console.Write(string.Join(",", a));

    }
}

关于c# - 如何将 IEnumerable<string> 转换为一个逗号分隔的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7481964/

相关文章:

c# - 从类、代码生成 XSD

c++ - c++ 中字节的十六进制值到字符串(相当于 od -x 在 linux 中)?

sql-server - SSRS——多值参数字符串操作

c# - SQL Server Profiler 中的 "Audit Logout"是什么?

c# - LINQ to Entities 无法识别方法 'System.DateTime ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' 方法

c# - 当字符串包含多个双引号时,从字符串中提取 URL 的正则表达式失败?

c# - UWP/C# 如何将 Comboboxitem 选择保存为 Sqlite 中的字符串

c# - 您如何将 { 和 } 放入格式字符串中

没有 <string> 和 STL 的 C++ 字符串

c# - 从 .Net WinForms 应用程序以编程方式刷新浏览器页面