I want to create a strongly typed multidimensional array or collection containing the following values from a database:
- FileName (As String)
- FileSize (As Integer)
Requirements:
- Accessible via index (e.g. Arr(i)(j), Arr.Row(i), etc)
- Efficient (i.e. fast & not resource intensive)
- Easily manipulated, added to, appended, etc.
- .NET 3.5 compatible
Thanks for the great answers everyone. Here’s what I went with… 🙂
Structure FileRecord
Dim Name As String
Dim Size As Integer
Sub New(ByVal FileName As String, ByVal FileSize As Integer)
Me.Name = FileName
Me.Size = FileSize
End Sub
Sub New(ByVal Files() As FileRecord)
For Each f As FileRecord In Files
Dim fr As New FileRecord(f.Name, f.Size)
Next
End Sub
End Structure
You can’t have a multidimensional array containing two separate types.
Instead, you’d typically make a single dimensional array (or
List(Of T)) containing a custom class with your data.In your case, you might want something like:
Then, make a
List(Of FileRecord)to hold your data. You’d then be able to access this as: