Two C# idioms: On Dictionaries

from blog Just Some Code, | ↗ original
This part of the C# idioms series is only about dictionaries. Let’s get rid of exceptions when working with dictionaries. Instead of checking if a dictionary contains an item before adding it, use TryAdd TryAdd() will return if an item was added or not to the dictionary. Unlike Add(), if the given key is already in the dictionary, TryAdd() won’t...