SafeDictionaryTKey, TValueAdd Method |
Adds the value to the dictionary if it does not exist.
Updates existing, if it does exist.
Namespace: CMS.BaseAssembly: CMS.Base (in CMS.Base.dll) Version: 13.0.131
Syntax 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