Collections, Are they helpful for passing many parameters to method?

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

Can collections help me pass several parameters to a method? For example, I
need to pass 10 different string and integer values to one method. How would
I declare a Collections type, store these 10 string and int values into the
Collection, and then pass just the Collection with the Method call? It sure
beats typing every single value every time I want to invoke this method.
Thanks.
 
If the parameters represent an abstraction, you might want to create an
instance of the abstraction and pass an object reference.

Regards,
Jeff
 
More than that, it is even recommended by Refactoring patterns to introduce
a parameter class when passing a bunch of parameters to a method. The only
case when one should probably prefer a collection of some kind is when it is
expected that the set of parameters is rather undetermined at the moment and
might vary in the future.
 
Back
Top