Home > OS >  An array of objects with an array of objects as a field
An array of objects with an array of objects as a field

Time:02-18

I am trying to have a procedure return an array of objects and assign that to the property within a object.

shipment.item(i).stuff = GetStuffArray()

Get Stuff Array

    Public Function GetStuffArray() As Stuff()
        Dim stuff(5) As Stuff

         For i As Integer = 0 To stuff.Length
           stuff(i) = New Stuff
           stuff(i).things = "New Stuff"
         Next

        Return stuff

    End Function

I thought VB.NET was "nice" enough that I could just assign an array

Here is my classes

Public Class Shipments
    Public Property items() As items
    Public Property bad As Boolean = True
End Class

Public Class items
    Public Property stuff() As stuff
    Public Property property As String
End Class

Public Class stuff
    Public Property things As String
End Class

What am I missing here? I attempted to to define the size of shipment.item(i).stuff = New Stuff() but I can't seem to define the size.

ReDim doesn't seem to work, which makes me thing the implementation of my class is wrong. I used Paste Special in Visual Studio to create the class with JSON. So I would assume the class structure is correct.

ReDim shipment.item(i).stuff(length)

Resources I have accessed:
enter image description here

  • Related