Returning an array from a function?

T

Terry Olsen

I'm currently using the following function to return an ArrayList:

Private Function ADSIReturnComputers(ByVal BldgMnemonic As String) As
ArrayList
Dim x As New ArrayList

Using oDirectoryEntry As DirectoryEntry = New
DirectoryEntry("LDAP://us.ups.com")
Using oDirectorySearcher As DirectorySearcher = New
DirectorySearcher(oDirectoryEntry)

oDirectorySearcher.Filter =
"(&(ObjectClass=Computer)(cn=" & BldgMnemonic & "*))"

For Each oResult As SearchResult In
oDirectorySearcher.FindAll
x.Add(oResult.GetDirectoryEntry.Name)
Next

End Using
End Using

Return x
End Function

Is there an easy way to return just a static array of string? Or would
that be more work than it's worth?
 
C

Cor Ligthert [MVP]

Terry,

Your question can be confusing, do you mean return a "static" arraylist as
it is in the context of Visual Basis inside a method?

Than you should pass that in my idea that arraylist just byval to the
method.

Cor
 
M

Mattias Sjögren

Is there an easy way to return just a static array of string? Or would
that be more work than it's worth?

Return CType(x.ToArray(GetType(String)), String())


Mattias
 
H

Heikki Leivo

Return CType(x.ToArray(GetType(String)), String())

Or more simply,

Dim x As New List(Of String)
....
Return x.ToArray()

-h-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top