SynchronizedDictionary
Represents a thread-safe dictionary that provides synchronization for its operations.
Implements: ISynchronizedCollection<KeyValuePair<T, T>>, ISynchronizedCollection, ISynchronizable, ICollection<KeyValuePair<T, T>>, IEnumerable<KeyValuePair<T, T>>, IEnumerable, IDictionary<T, T>
Constructors
public SynchronizedDictionary()
synchronizedDictionary = SynchronizedDictionary()
Initializes a new instance of the SynchronizedDictionary class.
protected SynchronizedDictionary(IDictionary<TKey, TValue> inner)
synchronizedDictionary = SynchronizedDictionary(inner)
Initializes a new instance of the SynchronizedDictionary class with the specified inner dictionary.
- inner
- The inner dictionary to wrap.
public SynchronizedDictionary(int capacity, IEqualityComparer<TKey> comparer)
synchronizedDictionary = SynchronizedDictionary(capacity, comparer)
Initializes a new instance of the SynchronizedDictionary class with the specified initial capacity and equality comparer.
- capacity
- The initial number of elements that the dictionary can contain.
- comparer
- The equality comparer to use when comparing keys.
public SynchronizedDictionary(IEqualityComparer<TKey> comparer)
synchronizedDictionary = SynchronizedDictionary(comparer)
Initializes a new instance of the SynchronizedDictionary class with the specified equality comparer.
- comparer
- The equality comparer to use when comparing keys.
public SynchronizedDictionary(int capacity)
synchronizedDictionary = SynchronizedDictionary(capacity)
Initializes a new instance of the SynchronizedDictionary class with the specified initial capacity.
- capacity
- The initial number of elements that the dictionary can contain.
Properties
public int Count { get; }
value = synchronizedDictionary.Count
Gets the number of key-value pairs contained in the dictionary.
public bool IsReadOnly { get; }
value = synchronizedDictionary.IsReadOnly
Gets a value indicating whether the dictionary is read-only.
public virtual TValue Item { get; set; }
value = synchronizedDictionary.Item
synchronizedDictionary.Item = value
Gets or sets the value associated with the specified key.
- key
- The key of the value to get or set.
Returns: The value associated with the specified key.
public ICollection<TKey> Keys { get; }
value = synchronizedDictionary.Keys
Gets a collection containing the keys in the dictionary.
public Lock SyncRoot { get; }
value = synchronizedDictionary.SyncRoot
Gets the synchronization root object used to synchronize access to the dictionary.
public ICollection<TValue> Values { get; }
value = synchronizedDictionary.Values
Gets a collection containing the values in the dictionary.
Methods
public virtual void Add(TKey key, TValue value)
synchronizedDictionary.Add(key, value)
Adds the specified key and value to the dictionary.
- key
- The key of the element to add.
- value
- The value of the element to add.
public void Add(KeyValuePair<TKey, TValue> item)
synchronizedDictionary.Add(item)
Adds a key-value pair to the dictionary.
- item
- The key-value pair to add.
public virtual void Clear()
synchronizedDictionary.Clear()
Removes all keys and values from the dictionary.
public bool Contains(KeyValuePair<TKey, TValue> item)
result = synchronizedDictionary.Contains(item)
Determines whether the dictionary contains a specific key-value pair.
- item
- The key-value pair to locate in the dictionary.
Returns: true if the dictionary contains the key-value pair; otherwise, false.
public virtual bool ContainsKey(TKey key)
result = synchronizedDictionary.ContainsKey(key)
Determines whether the dictionary contains the specified key.
- key
- The key to locate in the dictionary.
Returns: true if the dictionary contains an element with the specified key; otherwise, false.
public virtual void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
synchronizedDictionary.CopyTo(array, arrayIndex)
Copies the elements of the dictionary to an array, starting at a particular array index.
- array
- The one-dimensional array that is the destination of the elements copied from the dictionary.
- arrayIndex
- The zero-based index in at which copying begins.
public Scope EnterScope()
result = synchronizedDictionary.EnterScope()
Enters a synchronized scope for thread-safe operations on the collection.
Returns: A Scope that represents the synchronized scope.
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
result = synchronizedDictionary.GetEnumerator()
Returns an enumerator that iterates through the dictionary.
Returns: An enumerator that can be used to iterate through the dictionary.
public virtual bool Remove(TKey key)
result = synchronizedDictionary.Remove(key)
Removes the value with the specified key from the dictionary.
- key
- The key of the element to remove.
Returns: true if the element is successfully found and removed; otherwise, false.
public bool Remove(KeyValuePair<TKey, TValue> item)
result = synchronizedDictionary.Remove(item)
Removes the first occurrence of a specific key-value pair from the dictionary.
- item
- The key-value pair to remove.
Returns: true if the key-value pair was successfully removed; otherwise, false.
System#Collections#IEnumerable#GetEnumerator()
Returns an enumerator that iterates through the dictionary.
Returns: An enumerator that can be used to iterate through the dictionary.
public virtual bool TryGetValue(TKey key, TValue value)
result = synchronizedDictionary.TryGetValue(key, value)
Gets the value associated with the specified key.
- key
- The key of the value to get.
- value
- When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter.
Returns: true if the dictionary contains an element with the specified key; otherwise, false.