假设出于调试目的,我想快速将 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/