Table of Contents

Class ObservableConcurrentDictionary<TKey, TValue>

Namespace
Tharga.Toolkit
Assembly
Tharga.Toolkit.Standard.dll

A thread-safe dictionary that raises collection and property change notifications when items are added, removed, or modified.

public class ObservableConcurrentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged

Type Parameters

TKey

The type of keys in the dictionary.

TValue

The type of values in the dictionary.

Inheritance
ObservableConcurrentDictionary<TKey, TValue>
Implements
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IEnumerable<KeyValuePair<TKey, TValue>>
Inherited Members
Extension Methods

Properties

Count

public int Count { get; }

Property Value

int

IsReadOnly

public bool IsReadOnly { get; }

Property Value

bool

this[TKey]

Gets or sets the value for a key. Setting a new key raises Add; setting an existing key raises Replace with the old and the new value.

public TValue this[TKey key] { get; set; }

Parameters

key TKey

Property Value

TValue

Keys

public ICollection<TKey> Keys { get; }

Property Value

ICollection<TKey>

Values

public ICollection<TValue> Values { get; }

Property Value

ICollection<TValue>

Methods

Add(KeyValuePair<TKey, TValue>)

public void Add(KeyValuePair<TKey, TValue> item)

Parameters

item KeyValuePair<TKey, TValue>

Add(TKey, TValue)

Adds the key and value.

public void Add(TKey key, TValue value)

Parameters

key TKey
value TValue

Exceptions

ArgumentException

The key already exists. Use TryAdd(TKey, TValue) to add only when the key is missing.

Clear()

public void Clear()

Contains(KeyValuePair<TKey, TValue>)

public bool Contains(KeyValuePair<TKey, TValue> item)

Parameters

item KeyValuePair<TKey, TValue>

Returns

bool

ContainsKey(TKey)

public bool ContainsKey(TKey key)

Parameters

key TKey

Returns

bool

CopyTo(KeyValuePair<TKey, TValue>[], int)

public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)

Parameters

array KeyValuePair<TKey, TValue>[]
arrayIndex int

GetEnumerator()

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<TKey, TValue>>

OnCollectionChanged(NotifyCollectionChangedEventArgs)

protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)

Parameters

e NotifyCollectionChangedEventArgs

OnPropertyChanged(string)

protected virtual void OnPropertyChanged(string name)

Parameters

name string

Remove(KeyValuePair<TKey, TValue>)

Removes the key only when its value equals the value of item.

public bool Remove(KeyValuePair<TKey, TValue> item)

Parameters

item KeyValuePair<TKey, TValue>

Returns

bool

Remove(TKey)

public bool Remove(TKey key)

Parameters

key TKey

Returns

bool

TryAdd(TKey, TValue)

Adds the key and value if the key does not exist yet, raising the same notifications as Add(TKey, TValue).

public bool TryAdd(TKey key, TValue value)

Parameters

key TKey
value TValue

Returns

bool

true if the key and value were added; false if the key already exists.

TryGetValue(TKey, out TValue)

public bool TryGetValue(TKey key, out TValue value)

Parameters

key TKey
value TValue

Returns

bool

Events

CollectionChanged

public event NotifyCollectionChangedEventHandler CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

PropertyChanged

public event PropertyChangedEventHandler PropertyChanged

Event Type

PropertyChangedEventHandler