Tutorial by Examples

int[string] wordCount(string[] wordList) { int[string] words; foreach (word; wordList) { words[word]++; } return words; } void main() { int[string] count = wordCount(["hello", "world", "I", "say", "hello"]); ...
int[string] aa0 = ["x": 5, "y": 6]; //int values, string keys auto aa1 = ["x": 5.0, "y": 6.0]; // double values, string keys string[int] aa2 = [10: "A", 11: "B"]; //string values, int keys
int[string] aa = ["x": 5, "y": 6]; // The value can be set by its key: aa["x"] = 7; assert(aa["x"] == 7); // if the key does not exist will be added aa["z"] = 8; assert(aa["z"] == 8);
Let's assume an associative array aa: int[string] aa = ["x": 5, "y": 6]; Items can be removed by using .remove(), if key exits will be removed and remove returns true: assert(aa.remove("x")); if the given key does not exist remove does nothing and returns false:...
int[string] numbers = ["a" : 10, "b" : 20]; assert("a" in numbers); assert("b" in numbers); assert("c" in numbers);

Page 1 of 1