So I am writing a program which uses Dictionary to store objects. For example
var dictionary:Dictionary=new Dictionary();
var myObject = new myObject(var1, var2, var3);
dicionary["key"]=myObject;
where var1, var2, and var3 are simply means of assigning values to variables in myObject.
my question is, can I access values or functions that are found in myObject? In myObject class I have some getters and setters. Can I use a getter to get the value of var1 for example.
dictionary["keys"].getVar1()?
kind of thing.
Sure, just as
works, you can do it without the variable, in a single line.
Just beware of the type, you will get errors if
nullSo it might be a good idea to check for these things before accessing any methods directly.
However, if you are using Strings, a common
Objectis the usual solution. It works as an associative array:The
Dictionaryon the other hand is used when you need non-string objects as keys.One last note: class names are usually written in
CamelCase