Returning an array from a function?

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
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?
 
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
 
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
 
Return CType(x.ToArray(GetType(String)), String())

Or more simply,

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

-h-
 
Back
Top