我们在开发中经常会用List<string>来保存一组字符串,比如下面这段代码:
List<string> studentNames = new List<string>(); studentNames.Add("John"); studentNames.Add("Mary"); studentNames.Add("Rose");
可是有时候,我们要从中获取一个字符串,字符串的内容就是集合中的内容,但是要用逗号隔开,下面的办法可以实现:
string.Join(", ", studentNames.ToArray())
上面这条语句,返回的结果应该是下面这个样子:
John, Mary, Rose
或者直接转换为字符串数组
String[] convertedStringArray= studentNames.ToArray();
转载于:https://www.cnblogs.com/Mblog/archive/2010/03/08/1680975.html
相关资源:JAVA上百实例源码以及开源项目