【问题标题】:How I can Join this Array in a fast way?我怎样才能快速加入这个数组?
【发布时间】:2013-06-09 03:42:54
【问题描述】:

如何快速加入这个数组?:

Dim NewArray As Array = {"a", "b", "c"}
MsgBox(String.Join(vbNewLine, NewArray)) ' Result: System.String[]

问题是我加入时无法打印数组的内容,请看代码中的“结果”注释。

谢谢。

【问题讨论】:

    标签: .net arrays vb.net


    【解决方案1】:

    听起来你想要的是这样的

    Dim NewArray As String() = {"a", "b", "c"}
    MsgBox(String.Join(vbNewLine, NewArray)) ' Result: a b c
    

    或者,使用 Linq 的 Cast 扩展方法,它可以与任何非泛型 IEnumerable 一起使用,包括 Array 类型:

    Dim NewArray As Array = {"a", "b", "c"}
    MsgBox(String.Join(",", NewArray.Cast(Of String))) ' Result: a b c
    

    【讨论】:

    • 是的,这正是我需要的(嗯,换行符而不是空格,但是是的)
    • @pitoloko 是的,每个条目之间都会有新的行,我只想在一行上发表评论。
    • 但我需要使用我的问题中看到的数组类型,而不是数组(字符串)类型
    • 在这里看到我的新问题,如果可以提供帮助,再次感谢:stackoverflow.com/questions/17006522/…
    【解决方案2】:

    这是最快的方法。有什么问题吗?

    试试:

    Dim NewArray() As String = {"a", "b", "c"}
    

    【讨论】:

    • 是的,对不起,也许我没有提出好的问题,问题是我加入时无法打印数组的内容,请参见代码上的注释行
    • 它回答了这个问题。
    • +1 VB.Net 不是我的主要语言,但似乎这个解决方案和我的一样有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2021-08-01
    • 1970-01-01
    • 2011-09-27
    • 2021-07-31
    相关资源
    最近更新 更多