Is it possible to have a function that takes (int n,bool wantall) and returns a different type based on the bool?
The example that made me think about this was generate the fibonacci numbers.
If wantall = true, then return an array (or list) of the first n numbers, else, just return the nth number.
Is there a way to do this?
Is it possible to have a function that takes (int n,bool wantall) and returns
Share
No, you can’t change the return type.
For your example, ideally you should have different overloads for what you are talking about
Passing in a
boolfor this is just ugly.But if you insist on a single method
But, please, don’t do this.