Method Parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.Count -1
'do stuff with MyArrayList(i)
Next
End Sub
 
I had thought of passing an array, but was hoping there was somthing better.
Thanks, Cor, for showing me the parameter array.

Nathan
 

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

Back
Top