System.NullReference Exception Adding to a Dictionary [Answered]
I'm really confused why this is happening.
The dictionary in question is an attribute of a class that I've created.
Lecturer class:
I definitely do instantiate a new Lecturer object:
However, it refuses to assign the values taken from the SQL reader into the lecturer's dictionary attribute (CourseLecturers)
In the images attached, you can see that the reader successfully assigns the relevant values from the DB table into the variables, but the variables cannot be assigned to the dictionary for some reason. This is driving me insane, I've been debugging for 6 hours
8 Replies
I suspect it's because it's trying to {get} from empty dictionary before it invokes {set}, but I don't know how to get around this
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Oh i fixed it by declaring
in the constructor but your syntax looks way neater, i will try it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Huh
Idgi
you can use
= new()
instead of = new Dictionary<string, string>()
to save some spaceUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
✅ This post has been marked as answered!