我写了这个 – 非常简单 – 函数,然后想知道VB有一些预先构建的功能来做到这一点,但找不到任何具体的东西.
Private Shared Function MakeArray(Of T)(ByVal ParamArray args() As T) As T() Return args End Function
与其说是用的不多
Dim someNames() as string = MakeArray("Hans","Luke","Lia")
因为这可以做到
Dim someNames() as string = {"Hans","Lia"}
但更像是
public sub PrintNames(names() as string) // print each name End Sub PrintNames(MakeArray("Hans","Lia"))
有任何想法吗?
任何不做的理由:
原文链接:https://www.f2er.com/vb/255807.htmlDim someNames() as string = New String()("Han","Leia")
唯一的区别是类型推断,据我所知.
我刚检查过,VB 9也有implicitly typed arrays:
Dim someNames() as string = { "Han","Leia" }
(据我所知,这在VB 8中不起作用,但是显式版本会.隐式版本对于匿名类型是必需的,这对于VB 9也是新的.)