Click or drag to resize
SafeDictionaryTKey, TValueAdd Method
Adds the value to the dictionary if it does not exist. Updates existing, if it does exist.

Namespace: CMS.Base
Assembly: CMS.Base (in CMS.Base.dll) Version: 13.0.131
Syntax
C#
public override void Add(
	Object key,
	Object value
)

Parameters

key
Type: SystemObject
Key
value
Type: SystemObject
Value

Implements

IDictionaryAdd(Object, Object)
Examples
If you want to add some key-value pair only if it does not exist within the dictionary, use the following snippet to do so in a thread-safe way.
if (!dictionary.ContainsKey(myKey))
{
    lock (dictionary.SyncRoot)
    {
        if (!dictionary.ContainsKey(myKey))
        {
            dictionary.Add(myKey, myValue);
        }
    }
}
See Also