I need to add key/object pairs to a dictionary, but I of course need to first check if the key already exists otherwise I get a \"key already exists in dictionary
As usual John Skeet gets in there with lighting speed with the right answer, but interestingly you could also have written your SafeAdd as an Extension Method on IDictionary.
public static void SafeAdd(this IDictionary. dict, K key, T value)...