DEV Community

Jesse Phillips
Jesse Phillips

Posted on

3

Add to a Dictionary in D

Dictionary, hash table, associative array, map it has many names. The main challenge with dictionary adds is more around nested associative arrays, are you going to be annoyed if I select a different name every time?

int[string] dict;
dict["Key"] = 55;
Enter fullscreen mode Exit fullscreen mode

There is a Dictionary literal in D.

auto data = ["key" : 55]
Enter fullscreen mode Exit fullscreen mode

but this is not good for adding data as it will replace the variable with a new object. However if you're nesting and the inner dictionary might be null it can be good to use for starting a dictionary.

string[int][string] data;
data["hello"] = [95: "value"];
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay