I have two classes, A and B, with B as a property of A:
' if I call the A class everything is OK:
Dim x As New A
x.note = "Hello"
'but if I try to instantiate B I get errors:
x.item(0) = New B '-Throws a runtime error 'Object reference not set to instance' error, or
x.item = New B 'throws a compile time error 'Value of type 'B' cannot be converted to '1-dimensional array of B'
I know this must be a very simple thing but I am stuck. How can I instantiate x.item()? Thanks
VB.NET:
Public Class A
Private aField As String
Private itemField() As B
Public Property note() As String
Get
Return Me.aField
End Get
Set(ByVal value As String)
Me.aField = value
End Set
End Property
Public Property item() As B()
Get
Return Me.itemField
End Get
Set(ByVal value As B())
Me.itemField = value
End Set
End Property
End Class
Public Class B
Private bField As String
Public Property name() As String
Get
Return Me.bField
End Get
Set(ByVal value As String)
Me.bField = value
End Set
End Property
End Class
Dim x As New A
x.note = "Hello"
'but if I try to instantiate B I get errors:
x.item(0) = New B '-Throws a runtime error 'Object reference not set to instance' error, or
x.item = New B 'throws a compile time error 'Value of type 'B' cannot be converted to '1-dimensional array of B'
I know this must be a very simple thing but I am stuck. How can I instantiate x.item()? Thanks