本文介绍了如何加入一个ArrayList将其转换为字符串重新presentation的要素是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经一个ArrayList,并加入其所有的元素在一个字符串分隔余米使用...
I 've an ArrayList and to join all its elements with a separator in one string I m using...
Dim s As String = String.Join(",", TryCast(myArrayList.ToArray(GetType(String)), String()))
不过,我想知道是否有一个更聪明/更短的方法来得到相同的结果,或同一code,它看起来更好......
however, I would know if there is a smarter/shorter method to get the same result,or same code that looks better...
感谢你在前进,
最大
推荐答案
在Framework 4中是非常简单的:
In Framework 4 it is really simple:
var s = string.Join(",", myArrayList);
在3.5与LINQ的扩展方法:
In 3.5 with LINQ's extension methods:
var s = string.Join(",", myArrayList.Cast<string>().ToArray());
这些都短,但不聪明了。
These are shorter but not smarter.
我不知道他们是如何应写入VB.NET。
I have no idea how they should be written with VB.NET.
这篇关于如何加入一个ArrayList将其转换为字符串重新presentation的要素是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!