C#列表<串GT;以字符串分隔符 [英] C# List<string> to string with delimiter

查看:101
本文介绍了C#列表<串GT;以字符串分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在C#中的函数一些集合快速转换为字符串和分隔符分隔值

Is there a function in C# to quickly convert some collection to string and separate values with delimiter?

例如:

列表<串GT;名字 - > 字符串names_together =约翰,安娜,莫妮卡

推荐答案

您可以使用 的string.join 。如果你有一个列表与LT;串> ,那么你可以调用的 的ToArray 第一:

You can use String.Join. If you have a List<string> then you can call ToArray first:

List<string> names = new List<string>() { "John", "Anna", "Monica" };
var result = String.Join(", ", names.ToArray());

在.NET 4中,你不需要的ToArray 了,因为有> 的string.join 的IEnumerable<串>

In .NET 4 you don't need the ToArray anymore, since there is an overload of String.Join that takes an IEnumerable<string>.

这篇关于C#列表&LT;串GT;以字符串分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆