Prev | Current Page 122 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Instead, you are offered simple methods for
basic procedures. For example, to add an item to a Hash , you use the set method:
var myHash : Hash < String > = new Hash();
myHash.set(???newKey???, ???someValue???);
If you then want to retrieve the value of this key, you would use the get method:
var myValue = myHash.get(???newKey???);
You can then remove the key and its paired value from the Hash using remove :
myHash.remove(???newKey???);
Once you remove your key, querying the key again results in a null value. In order to check that a key
exists before you query it, you can use the exists method:
var doesExist : Bool = myHash.exists(???newKey???);
If the key exists, the method will return true. Otherwise, false is returned.
Part I: The Core Language
50
To get a better feel for the Hash type, enter the following code and save it as HashTest.hx :
class HashTest
{
static public function main()
{
var myHash : Hash < Int > = new Hash();
myHash.set(???one???, 1);
myHash.set(???two???, 2);
myHash.set(???three???, 3);
trace(myHash.


Pages:
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134