J
John Dann
I'm getting an NullReferenceException that I don't understand when
trying to access an array of objects within another object. In
simplified terms the code I'm trying to use is as follows:
Public Class MyInnerClass
Public Name as String
' And other public properties
End Class
Public Class MyMainClass
Dim m_InnerObjects() as MyInnerClass
Friend Property InnerObjs(ByVal i as Integer) as MyInnerClass
Get
Return m_InnerObjects(i)
End Get
Set (ByVal value as MyInnerClass)
m_InnerObjects(i) = value
End Set
End Property
End Class
'Within main module
Dim oMMC as New MyMainClass
oMMC.InnerObjects(some-integer).Name = some-string
It's this last line that throws the NullReferenceException. The above
is just a skeleton of the code - I've omitted a lot of detail like
dimensioning the array of MyInnerClass.
But can anyone spot if there's anything fundamental wrong with what
I'm trying to do here? Or is the problem maybe in the extra detail
that I haven't given?
Maybe there's a better way of managing the collection of MyInnerClass
objects than using an array?
Many thanks
JGD
trying to access an array of objects within another object. In
simplified terms the code I'm trying to use is as follows:
Public Class MyInnerClass
Public Name as String
' And other public properties
End Class
Public Class MyMainClass
Dim m_InnerObjects() as MyInnerClass
Friend Property InnerObjs(ByVal i as Integer) as MyInnerClass
Get
Return m_InnerObjects(i)
End Get
Set (ByVal value as MyInnerClass)
m_InnerObjects(i) = value
End Set
End Property
End Class
'Within main module
Dim oMMC as New MyMainClass
oMMC.InnerObjects(some-integer).Name = some-string
It's this last line that throws the NullReferenceException. The above
is just a skeleton of the code - I've omitted a lot of detail like
dimensioning the array of MyInnerClass.
But can anyone spot if there's anything fundamental wrong with what
I'm trying to do here? Or is the problem maybe in the extra detail
that I haven't given?
Maybe there's a better way of managing the collection of MyInnerClass
objects than using an array?
Many thanks
JGD