Reputation: 601
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
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