如何转换IEnumerable< string>一个逗号分隔的字符串? [英] How to convert IEnumerable<string> to one comma separated string?
本文介绍了如何转换IEnumerable< string>一个逗号分隔的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说,出于调试目的,我想快速将IEnumerable的内容转换为单行字符串,并用逗号分隔每个字符串项.我可以使用带有foreach循环的辅助方法来完成此操作,但这既不有趣也不简短.可以使用Linq吗?还有其他一些短线方法吗?
Say that for debugging purposes, I want to quickly get the contents of an IEnumerable into one-line string with each string item comma-separated. I can do it in a helper method with a foreach loop, but that's neither fun nor brief. Can Linq be used? Some other short-ish way?
推荐答案
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));
}
}
这篇关于如何转换IEnumerable< string>一个逗号分隔的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文