如何声明嵌套的结构数组 [英] How do I declare nested arrays of structures

查看:70
本文介绍了如何声明嵌套的结构数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我的问题是如何在VB.Net中声明一个嵌套的结构数组(如果这就是你所说的那样)



基本上我想这样做:



Hi all

My question is how to declare a nested array of structures (If that is what you call it) in VB.Net

Essentially I would like to do this:

Year(5).Month(3).Day(3) = 123 '(arbitary number)





我是VB.NET的新手,如果有人问过这个问题,我很抱歉



非常感谢任何链接或评论



I'm new to VB.NET and I apologise if this has been asked before

Any link or comment would be greatly appreciated

推荐答案

在.NET中声明嵌套存储结构的方法有很多种(多维数组,集合集合) [收藏品!]等)



选择可能是个人偏好的问题,也可能是您想要对嵌套层次结构的每个级别做什么。但是,以上都不会为您提供您所说的确切语法。更典型的是Day(5,3,3)= 123或Day(5)(3)(3)= 123.



提供您需要的语法您可以使用年份和月份的谨慎课程:

具有月份属性的年份,其获取索引并管理列表(月份)

具有以下属性的月份一天,它取一个索引并管理一个List(整数)?



一个考虑因素是将123指定为日意味着什么?您可能需要课程天来解释,范围检查等。



您确定不能使用内置的抽象日期/时间数据类型?



我强烈建议您阅读List类作为可以声明为(Of Type)的容器。另外,请注意使用可能是保留字(或VB全局命名空间的成员)的对象名称,例如Month和Year(请注意,我使用了复数作为类名!)



为这样的一般性问题提供更全面的解决方案更难,但我想我已经回答了你的具体问题?
There are many ways to declare nested storage stucture in .NET (multi-deimensional arrays, collections of collections [of collections!], etc.)

Choice may be a matter of personal preference or exactly what you want to do with each level of that nested hierarchy. However, none of the above would give you the exact syntax that you state. More typical would be Day(5,3,3) = 123 or Day(5)(3)(3) = 123.

To give the syntax you require you could use discreet classes for Years and Months:
Years having a property of Month, which takes an index and manages a List (Of Months)
Months having a property of Day, which takes an index and manages a List (Of Integer)?

One consideration is what does assigning 123 to a "day" mean? You may need a Class "Days" to interpret, range check etc..

Are you sure that you can't use the in-built abstract date/time data type?

I strongly suggest reading up on the "List" class as a container which can be declared "(Of Type)". Also, be careful about using object names that may be reserved words (or members of the VB global namespace) like Month and Year (note that I used plurals for the class names!)

It's harder to give a more comprehensive solution for such a general question, but I think I've answered your specific enquiry?


Module Module1

    Sub Main()

        Dim Year As Year = New Year()

        Year(5).Month(11).Day(3) = 123

    End Sub

End Module

Class Year
    Inherits List(Of Year)

    Public Month(12) As Month

End Class

Class Month
    Inherits List(Of Month)

    Public Day(31) As Integer
End Class


这篇关于如何声明嵌套的结构数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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