Home All Groups Group Topic Archive Search About

Returning an array from a function?

Author
29 Aug 2006 3:31 AM
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?


*** Sent via Developersdex http://www.developersdex.com ***

Author
29 Aug 2006 5:41 AM
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

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> schreef in bericht
news:eYvpPuxyGHA.4844@TK2MSFTNGP04.phx.gbl...
> 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?
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
29 Aug 2006 5:48 AM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
29 Aug 2006 9:52 AM
Heikki Leivo
> Return CType(x.ToArray(GetType(String)), String())

Or more simply,

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

-h-