Method Parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan M

    #1

    Method Parameters

    Hi,

    I was wondering if there was a way to create a method that would accept an
    unlimited number of objects in its parameters without specifying ahead of
    time how many objects may be passed. One time I might want to pass just one
    object, another time 5 or ten. But I don't want to create separate
    overloaded methods for each scenario. Is there a way to do this? How about
    another way to get something of the same effect without creating numerous
    overloaded methods?

    Thanks,
    Nathan
  • Terry Olsen

    #2
    Re: Method Parameters

    How about using an ArrayList. Put all the parameters you want in the
    ArrayList and pass that...

    Private MySub(ByVal MyArrayList as ArrayList)
    For i as integer = 0 to MyArrayList.Cou nt -1
    'do stuff with MyArrayList(i)
    Next
    End Sub

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

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Method Parameters

      Nathan,

      In my opinion is what you ask quiet standard in VBNet

      Parameter array

      http://msdn.microsoft.com/library/de...aramarrays.asp

      I hope this helps,

      Cor


      Comment

      • Nathan M

        #4
        RE: Method Parameters

        I had thought of passing an array, but was hoping there was somthing better.
        Thanks, Cor, for showing me the parameter array.

        Nathan

        Comment

        Working...