如何连接 ArrayList 的元素将其转换为字符串表示? [英] How to join elements of an ArrayList converting it to a string representation?

查看:71
本文介绍了如何连接 ArrayList 的元素将其转换为字符串表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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()))

但是,我想知道是否有更智能/更短的方法来获得相同的结果,或看起来更好的相同代码...

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 的元素将其转换为字符串表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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