在 C# 中将列表转换为字符串 [英] Convert a list to a string in C#
本文介绍了在 C# 中将列表转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 C# 中将列表转换为字符串?
How do I convert a list to a string in C#?
当我在 List 对象上执行 toString
时,我得到:
When I execute toString
on a List object, I get:
System.Collections.Generic.List`1[System.String]
System.Collections.Generic.List`1[System.String]
推荐答案
也许你正在尝试做
string combindedString = string.Join( ",", myList.ToArray() );
您可以将,"替换为您想要拆分列表中元素的内容.
You can replace "," with what you want to split the elements in the list by.
编辑:正如评论中提到的,你也可以这样做
Edit: As mention in the comments you could also do
string combindedString = string.Join( ",", myList);
参考:
Join<T>(String, IEnumerable<T>)
Concatenates the members of a collection, using the specified separator between each member.
这篇关于在 C# 中将列表转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文