ImmutableDictionary<TKey,TValue> Class

Definition

Represents an immutable, unordered collection of keys and values.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

generic <typename TKey, typename TValue>
public ref class ImmutableDictionary sealed : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IDictionary<TKey, TValue>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyCollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyDictionary<TKey, TValue>, System::Collections::IDictionary, System::Collections::Immutable::IImmutableDictionary<TKey, TValue>
public sealed class ImmutableDictionary<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary, System.Collections.Immutable.IImmutableDictionary<TKey,TValue>
type ImmutableDictionary<'Key, 'Value> = class
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IEnumerable
    interface IDictionary<'Key, 'Value>
    interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
    interface IReadOnlyDictionary<'Key, 'Value>
    interface ICollection
    interface IDictionary
    interface IImmutableDictionary<'Key, 'Value>
Public NotInheritable Class ImmutableDictionary(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue)), IImmutableDictionary(Of TKey, TValue), IReadOnlyCollection(Of KeyValuePair(Of TKey, TValue)), IReadOnlyDictionary(Of TKey, TValue)

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Inheritance
ImmutableDictionary<TKey,TValue>
Implements

Remarks

When you manipulate an immutable dictionary a copy of the original dictionary is made, manipulations applied and a new immutable dictionary is returned.

Fields

Empty

Gets an empty immutable dictionary.

Properties

Count

Gets the number of key/value pairs in the immutable dictionary.

IsEmpty

Gets a value that indicates whether this instance of the immutable dictionary is empty.

Item[TKey]

Gets the TValue associated with the specified key.

KeyComparer

Gets the key comparer for the immutable dictionary.

Keys

Gets the keys in the immutable dictionary.

ValueComparer

Gets the value comparer used to determine whether values are equal.

Values

Gets the values in the immutable dictionary.

Methods

Add(TKey, TValue)

Adds an element with the specified key and value to the immutable dictionary.

AddRange(IEnumerable<KeyValuePair<TKey,TValue>>)

Adds the specified key/value pairs to the immutable dictionary.

Clear()

Retrieves an empty immutable dictionary that has the same ordering and key/value comparison rules as this dictionary instance.

Contains(KeyValuePair<TKey,TValue>)

Determines whether this immutable dictionary contains the specified key/value pair.

ContainsKey(TKey)

Determines whether the immutable dictionary contains an element with the specified key.

ContainsValue(TValue)

Determines whether the immutable dictionary contains an element with the specified value.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Returns an enumerator that iterates through the immutable dictionary.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TKey)

Removes the element with the specified key from the immutable dictionary.

RemoveRange(IEnumerable<TKey>)

Removes the elements with the specified keys from the immutable dictionary.

SetItem(TKey, TValue)

Sets the specified key and value in the immutable dictionary, possibly overwriting an existing value for the key.

SetItems(IEnumerable<KeyValuePair<TKey,TValue>>)

Sets the specified key/value pairs in the immutable dictionary, possibly overwriting existing values for the keys.

ToBuilder()

Creates an immutable dictionary with the same contents as this dictionary that can be efficiently mutated across multiple operations by using standard mutable interfaces.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TryGetKey(TKey, TKey)

Determines whether this dictionary contains a specified key.

TryGetValue(TKey, TValue)

Gets the value associated with the specified key.

WithComparers(IEqualityComparer<TKey>)

Gets an instance of the immutable dictionary that uses the specified key comparer.

WithComparers(IEqualityComparer<TKey>, IEqualityComparer<TValue>)

Gets an instance of the immutable dictionary that uses the specified key and value comparers.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the elements of the dictionary to an array, starting at a particular array index.

ICollection.IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>)
ICollection<KeyValuePair<TKey,TValue>>.Clear()
ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32)
ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly
ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>)
IDictionary.Add(Object, Object)

Adds an element with the provided key and value to the immutable dictionary object.

IDictionary.Clear()

Clears this instance.

IDictionary.Contains(Object)

Determines whether the immutable dictionary object contains an element with the specified key.

IDictionary.GetEnumerator()

Returns an IDictionaryEnumerator object for the immutable dictionary object.

IDictionary.IsFixedSize

Gets a value indicating whether the IDictionary object has a fixed size.

IDictionary.IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

IDictionary.Item[Object]

Gets or sets the element with the specified key.

IDictionary.Keys

Gets an ICollection<T> containing the keys of the IDictionary<TKey,TValue>.

IDictionary.Remove(Object)

Removes the element with the specified key from the immutable dictionary object.

IDictionary.Values

Gets an ICollection<T> containing the values in the IDictionary<TKey,TValue>.

IDictionary<TKey,TValue>.Add(TKey, TValue)
IDictionary<TKey,TValue>.Item[TKey]
IDictionary<TKey,TValue>.Keys
IDictionary<TKey,TValue>.Remove(TKey)
IDictionary<TKey,TValue>.Values
IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()
IImmutableDictionary<TKey,TValue>.Add(TKey, TValue)
IImmutableDictionary<TKey,TValue>.AddRange(IEnumerable<KeyValuePair<TKey,TValue>>)
IImmutableDictionary<TKey,TValue>.Clear()
IImmutableDictionary<TKey,TValue>.Remove(TKey)
IImmutableDictionary<TKey,TValue>.RemoveRange(IEnumerable<TKey>)
IImmutableDictionary<TKey,TValue>.SetItem(TKey, TValue)
IImmutableDictionary<TKey,TValue>.SetItems(IEnumerable<KeyValuePair<TKey,TValue>>)

Extension Methods

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

Tries to get the value associated with the specified key in the dictionary.

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)

Tries to get the value associated with the specified key in the dictionary.

Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)

Tries to remove the value with the specified key from the dictionary.

TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)

Tries to add the specified key and value to the dictionary.

Contains<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey, TValue)

Determines whether the specified immutable dictionary contains the specified key/value pair.

GetValueOrDefault<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey)

Gets the value for a given key if a matching key exists in the dictionary.

GetValueOrDefault<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey, TValue)

Gets the value for a given key if a matching key exists in the dictionary.

CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

Thread Safety

This type is thread safe.