I have a dictionary as one of the fields of the structure of the value part of another dictionary so that a course can contain multiple classes, each with its own teacher and students as below:
Structure course
Dim description As String
Structure classs
Dim teacherCode As String
Dim studentIDs() As Integer
End Structure
Dim classes As Dictionary(Of String, classs) 'key=classCode
End Structure
Structure courseKey
Dim name As String
Dim yearLevel As Short
End Structure
Dim courses As New Dictionary(Of courseKey, course)
I can construct a courseKey and create an empty courses dictionary entry using an empty classs sub-dictionary with courses.Add(courseKey, course), but I can't work out how (or, indeed, if it's possible) to create a new courses dictionary entry with a non-empty classs sub-dictionary. I expected to be able to do something like this to create a classs and then add it to the course, but get a NullReferenceException (even when courses(courseKey) references the appropriate dictionary item, and when classCode is a valid string and classs is a valid instance of the classs structure with data in it):
courses(courseKey).classes.Add(classCode, classs)
Am I missing something obvious? I was planning on having a few data structures like this, some with multiple dictionaries inside another dictionary. If this isn't possible, perhaps there's a better way?