daOnlyBG
daOnlyBG

Reputation: 601

How to pass an array of unknown dimension as a method argument?

Suppose I would like to create a method that takes 1-D or 2-D arrays as argument (for the present time, it wouldn't make sense to accept higher dimension arrays). I know I can simply create two different methods, but I'd like to keep just one, for sake of keeping my code short.

Is there a way to create such a method?

Upvotes: 1

Views: 201

Answers (1)

Eric J.
Eric J.

Reputation: 150108

I know I can simply create two different methods, but I'd like to keep just one, for sake of keeping my code short.

Define the processing that is common to both cases, and create a third (probably private) method that performs that calculation.

Create method overloads that accept both types of arrays, and have them call the third method to perform the processing that both cases have in common.

Upvotes: 1

Related Questions