将数组转换为字符串


81

如何将此输出转换为字符串?

List<string> Client = new List<string>();
foreach (string listitem in lbClients.SelectedItems)
{
    Client.Add(listitem);
}

3
什么类型的字符串?分隔符分隔了吗?
CodeLikeBeaker

您希望结果字符串看起来像什么?
Jon B

您正在使用哪个版本的.NET框架?在.NET 4中添加了建议的String.Join()重载,在此之前,该方法仅采用了Array。
Dan J

Answers:


198

您可以使用以下方法加入阵列:

string.Join(",", Client);

然后,您可以随时输出。您可以将逗号更改为任何所需的空格,管道或其他内容。



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.