如何加入一个ArrayList将其转换为字符串重新presentation的要素是什么?将其、字符串、转换为、要素

2023-09-06 07:23:31 作者:花落︶心微凉

我已经一个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.