Hey, it is not very clear what you are trying to do here, but here's my best guess (correct me if wrong):
You would like to have a single function which, when called, returns an array containing a collection of one of the properties of the Customer struct. in other words, the same function will sometimes return an array containing the city of each Customer instance, other times the country property.
If that is what you want, then you should be thinking about the function parameter(s) required to make it happen. The question becomes: How do I let the function know which properties to check in the for
loop.
Which you could achieve by using an enum that lists the properties, and then inside your function, you switch
over that enum. Each case will contain the for
loop relevant to that property.
Therefore, your function will need to take that enum as it's parameter.
Try it out, and if you still need help with it, do let us know. 😉