Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a string array from a function without initialising it first

Tags:

vb.net

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

Return bar
End Function

My situation is similar to the code 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?

like image 875
Richard Lucas Avatar asked Dec 10 '09 10:12

Richard Lucas


1 Answers

You could do this:

Public Function Foo() As String()
    Return New String() {"bar1", "bar2", "bar3"}
End Function
like image 137
Darin Dimitrov Avatar answered Oct 19 '22 10:10

Darin Dimitrov