I have a collection of items which I want to reference by their names - as it might be “ball”, “bat”, “stick”, etc. So a dictionary suggests itself. Now for each of these items, there are two integer properties, let’s say count1 and count2. The question is how to represent all this.
I tried making a new class (say, myitems) whose super is dictionary, and then adding two properties to it, count1 and count2. But having created the class, I couldn’t figure out how to use it, or if indeed it is possible. I tried such as:
dim mydict as new myitems
mydict.value("bat").count1 = 27
mydict.value("bat").count2 = 44
but the compiler rejected this. Is this the right approach but wrong syntax, somehow?
I’m also looking at just using a plain dictionary, and making a new class (say, myvals) with two properties, count1 and count2. Then I’d be doing:
dim mydict as new dictionary, vals as new myvals // Initialisation done somewhere in my code
vals.count1 = 27
vals.count2 = 44
mydict.value("bat") = vals
I’d prefer the former (if possible) since there is a requirement for count1 and count2 to be updated from time to time. I’d like to avoid doing the following:
dim mydict as new dictionary, vals as new myvals // Updating done elsewhere in my code
vals = mydict.value("bat")
vals.count1 = vals.count1 + 3
vals.count2 = vals.count2 - 7
mydict.value("bat") = vals
which seems rather heavy. Much better if I could say:
mydict.value("bat").count1 = mydict.value("bat").count1 + 3
mydict.value("bat").count2 = mydict.value("bat").count2 - 7
Or should I be using a different approach entirely?