开发者

Return a string array from a function without initialising it first

Public Function Foo() as String()
Dim bar As String = {"bar1","bar2","bar3"}

Return bar
End Function

My situation is similar to the co开发者_StackOverflowde sample above where I'm returning a string array from a function.

What I would like to do is just return the string array without having to declare a variable first and then return the variable.

Something like this, although this obviously doesn't work:

Return {"bar1","bar2","bar3"}

Is it possible to do this, I can't seem to find a method that works?


You could do this:

Public Function Foo() As String()
    Return New String() {"bar1", "bar2", "bar3"}
End Function


You do not have to declare a variable (as the example from Darin), but you do have to create an instance of the type you want (a string array).

His example works because he is "newing up" a string array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜