如何在vb.net中定义索引为字符串的三维数组 [英] how to defince three dimensional array whose index is string in vb.net

查看:45
本文介绍了如何在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

我将这些值保存在三维数组中,但我不知道如何实现.我想要这样的数组 myarray(country,state,city)=1.但不能在索引上分配字符串.有什么方法可以实现这个或任何其他方法来解决这个问题.谢谢

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

推荐答案

你不需要一个 3 维数组,你可以用一个带有复合索引的字典来代替.示例键:

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

如果缺少一个键,您可以留下一个斜线来说明 state = country 或 city 的情况(这种情况很少见,但理论上是可能的).所以为了避免混淆,请保持这样:

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

从某种意义上说,它比 3 维数组更好,因为您只存储所需的条目.为了可维护性,比 Dictionary(Of Dictionary(Of Dictionary...) 更好.

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.

这篇关于如何在vb.net中定义索引为字符串的三维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆