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 に答える