Returning an array from a function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry Olsen

    #1

    Returning an array from a function?

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

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

    Using oDirectoryEntry As DirectoryEntry = New
    DirectoryEntry( "LDAP://us.ups.com")
    Using oDirectorySearc her As DirectorySearch er = New
    DirectorySearch er(oDirectoryEn try)

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

    For Each oResult As SearchResult In
    oDirectorySearc her.FindAll
    x.Add(oResult.G etDirectoryEntr y.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 ***
  • Cor Ligthert [MVP]

    #2
    Re: Returning an array from a function?

    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

    "Terry Olsen" <tolsen64@hotma il.comschreef in bericht
    news:eYvpPuxyGH A.4844@TK2MSFTN GP04.phx.gbl...
    I'm currently using the following function to return an ArrayList:
    >
    Private Function ADSIReturnCompu ters(ByVal BldgMnemonic As String) As
    ArrayList
    Dim x As New ArrayList
    >
    Using oDirectoryEntry As DirectoryEntry = New
    DirectoryEntry( "LDAP://us.ups.com")
    Using oDirectorySearc her As DirectorySearch er = New
    DirectorySearch er(oDirectoryEn try)
    >
    oDirectorySearc her.Filter =
    "(&(ObjectClass =Computer)(cn=" & BldgMnemonic & "*))"
    >
    For Each oResult As SearchResult In
    oDirectorySearc her.FindAll
    x.Add(oResult.G etDirectoryEntr y.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 ***

    Comment

    • Mattias Sjögren

      #3
      Re: Returning an array from a function?

      >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.

      Comment

      • Heikki Leivo

        #4
        Re: Returning an array from a function?

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

        Or more simply,

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

        -h-


        Comment

        Working...