0

我正在编写的 Web 模块中有很多数组,随着时间的推移我会添加更多。我想动态枚举所有数组以搜索和更新它们。这可能吗?下面的代码片段:

Private EMASCFee() As String = {0, 1, "12345679", "MASC Debt SetOff Fees"}
Private EMSPen() As String = {2, 3, "987654312", "Medicare EMS Late Penalties"}
Private Beach() As String = {4, 5, "110022233", "Beach Services"}

Private allCodes() As Array 'Holds all Codes Arrays

Private Sub addArrays()    
    'Adds all Codes String Arrays together into 1 Array  *** Add NEW string arrays to the end of allCodes ***
    allCodes = {EMASCFee, EMSPen, Beach}
End Sub

我想做的是:

Private EMASCFee() As String = {0, 1, "12345679", "MASC Debt SetOff Fees"}
Private EMSPen() As String = {2, 3, "987654312", "Medicare EMS Late Penalties"}
Private Beach() As String = {4, 5, "110022233", "Beach Services"}

Private allCodes() As Array 'Holds all Codes Arrays

Private Sub addArrays()    
    For each myArray as Array in ModuleName
        allCodes = {allCodes, myArray}
    Next
End Sub
4

1 回答 1

1

如果您真的想坚持使用数组,可以使用以下方法:

Module Codes
    Private EMASCFee() As String = {0, 1, "12345679", "MASC Debt SetOff Fees"}
    Private EMSPen() As String = {2, 3, "987654312", "Medicare EMS Late Penalties"}
    Private Beach() As String = {4, 5, "110022233", "Beach Services"}

    Public Function GetAllCodes() As String()()
        Dim t = Type.GetType("WindowsApplication1.Codes") 'Change this to your project namespace
        Dim members = t.GetFields(Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Static)
        Dim result As New List(Of String())
        For Each m In members
            If m.FieldType = GetType(String()) Then
                result.Add(m.GetValue(Nothing))
            End If
        Next
        Return result.ToArray()
    End Function
End Module

但是,我真的建议使用结构和通用列表而不是数组。总体概念将是相同的。

于 2013-03-21T12:49:41.117 回答