Muhammad Ali Hassan
Muhammad Ali Hassan

Reputation: 962

how to defince three dimensional array whose index is string in vb.net

i want to display country, state and city name. These values are retrieved from a database. if the country name doesn't exist then only city and state name will display. If city and state name doesn't exist then only country name will display, as shown below:

country = totalno
country/state = totalno
country/state/city = totalno

I am saving these values in three dimensional array, but I don't know how to achieve this. i want my array like this myarray(country,state,city)=1. but can't assign string on index. Is there any way to achieve this or any other way to solve this. Thanks

Upvotes: 1

Views: 130

Answers (1)

Victor Zakharov
Victor Zakharov

Reputation: 26424

You don't need a 3-dimensional array, you can have a dictionary with a composite index instead. Example keys:

USA
USA/OH
Canada/ON/Toronto

If a key is missing, you can leave a slash to account for cases when state = country or city (which is rare, but theoretically possible). So to avoid confusion, leave it like this:

USA//
USA/OH/
Canada/ON/Toronto

It is better than a 3-dimensional array in a sense that you only store the entries you need. And better than a Dictionary(Of Dictionary(Of Dictionary... for maintainability purposes.

Upvotes: 2

Related Questions