Show / Hide Table of Contents

Class MultiValueDictionary<TKey, TValue>

A MultiValueDictionary can be viewed as a IDictionary that allows multiple values for any given unique key. While the MultiValueDictionary API is mostly the same as that of a regular IDictionary, there is a distinction in that getting the value for a key returns a IReadOnlyCollection<T> of values rather than a single value associated with that key. Additionally, there is functionality to allow adding or removing more than a single value at once.

The MultiValueDictionary can also be viewed as a IReadOnlyDictionary<TKey,IReadOnlyCollection<TValue>t> where the IReadOnlyCollection<T> is abstracted from the view of the programmer.

For a read-only MultiValueDictionary, see ILookup<TKey, TElement>.

Inheritance
Object
MultiValueDictionary<TKey, TValue>
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace:System.Collections.Generic
Assembly:FubarDev.WebDavServer.dll
Syntax
public class MultiValueDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, IReadOnlyCollection<TValue>>, IReadOnlyCollection<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, IEnumerable
Type Parameters
Name Description
TKey

The type of the key.

TValue

The type of the value.

Constructors

| Improve this Doc View Source

MultiValueDictionary()

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the default IEqualityComparer<T> for TKey.

Declaration
public MultiValueDictionary()
| Improve this Doc View Source

MultiValueDictionary(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the default IEqualityComparer<T> for the TKey type.

Declaration
public MultiValueDictionary(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable)
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

Exceptions
Type Condition
ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

MultiValueDictionary(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, IEqualityComparer<TKey>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the specified IEqualityComparer<T>.

Declaration
public MultiValueDictionary(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

MultiValueDictionary(IEqualityComparer<TKey>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the specified IEqualityComparer<T>.

Declaration
public MultiValueDictionary(IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

| Improve this Doc View Source

MultiValueDictionary(Int32)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the default IEqualityComparer<T> for TKey.

Declaration
public MultiValueDictionary(int capacity)
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

Exceptions
Type Condition
ArgumentOutOfRangeException

capacity must be >= 0

| Improve this Doc View Source

MultiValueDictionary(Int32, IEqualityComparer<TKey>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the specified IEqualityComparer<T>.

Declaration
public MultiValueDictionary(int capacity, IEqualityComparer<TKey> comparer)
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
ArgumentOutOfRangeException

Capacity must be >= 0

Properties

| Improve this Doc View Source

Count

Returns the number of TKeys with one or more associated TValue in this MultiValueDictionary<TKey, TValue>.

Declaration
public int Count { get; }
Property Value
Type Description
Int32

The number of TKeys in this MultiValueDictionary<TKey, TValue>.

Implements
IReadOnlyCollection<T>.Count
| Improve this Doc View Source

Item[TKey]

Get every TValue associated with the given TKey. If key is not found in this MultiValueDictionary<TKey, TValue>, will throw a KeyNotFoundException.

Declaration
public IReadOnlyCollection<TValue> this[TKey key] { get; }
Parameters
Type Name Description
TKey key

The TKey of the elements to retrieve.

Property Value
Type Description
IReadOnlyCollection<TValue>

An IReadOnlyCollection<T> containing every TValue associated with key.

Implements
IReadOnlyDictionary<TKey, TValue>.Item[TKey]
Remarks

Note that the IReadOnlyCollection<T> returned will change alongside any changes to the MultiValueDictionary<TKey, TValue>

Exceptions
Type Condition
ArgumentNullException

key must be non-null

KeyNotFoundException

key does not have any associated TValues in this MultiValueDictionary<TKey, TValue>.

| Improve this Doc View Source

Keys

Gets each TKey in this MultiValueDictionary<TKey, TValue> that has one or more associated TValue.

Declaration
public IEnumerable<TKey> Keys { get; }
Property Value
Type Description
IEnumerable<TKey>

An IEnumerable<T> containing each TKey in this MultiValueDictionary<TKey, TValue> that has one or more associated TValue.

Implements
IReadOnlyDictionary<TKey, TValue>.Keys
| Improve this Doc View Source

Values

Gets an enumerable of IReadOnlyCollection<T> from this MultiValueDictionary<TKey, TValue>, where each IReadOnlyCollection<T> is the collection of every TValue associated with a TKey present in the MultiValueDictionary<TKey, TValue>.

Declaration
public IEnumerable<IReadOnlyCollection<TValue>> Values { get; }
Property Value
Type Description
IEnumerable<IReadOnlyCollection<TValue>>

An IEnumerable of each IReadOnlyCollection<T> in this MultiValueDictionary<TKey, TValue>

Implements
IReadOnlyDictionary<TKey, TValue>.Values

Methods

| Improve this Doc View Source

Add(TKey, TValue)

Adds the specified TKey and TValue to the MultiValueDictionary<TKey, TValue>.

Declaration
public void Add(TKey key, TValue value)
Parameters
Type Name Description
TKey key

The TKey of the element to add.

TValue value

The TValue of the element to add.

Remarks

Unlike the Add for IDictionary, the MultiValueDictionary<TKey, TValue> Add will not throw any exceptions. If the given TKey is already in the MultiValueDictionary<TKey, TValue>, then TValue will be added to IReadOnlyCollection<T> associated with key

Exceptions
Type Condition
ArgumentNullException

key is null.

| Improve this Doc View Source

AddRange(TKey, IEnumerable<TValue>)

Adds a number of key-value pairs to this MultiValueDictionary<TKey, TValue>, where the key for each value is key, and the value for a pair is an element from values

Declaration
public void AddRange(TKey key, IEnumerable<TValue> values)
Parameters
Type Name Description
TKey key

The TKey of all entries to add

IEnumerable<TValue> values

An IEnumerable<T> of values to add

Remarks

A call to this AddRange method will always invalidate any currently running enumeration regardless of whether the AddRange method actually modified the MultiValueDictionary<TKey, TValue>.

Exceptions
Type Condition
ArgumentNullException

key and values must be non-null

| Improve this Doc View Source

Clear()

Removes every TKey and TValue from this MultiValueDictionary<TKey, TValue>.

Declaration
public void Clear()
| Improve this Doc View Source

Contains(TKey, TValue)

Determines if the given TKey-TValue pair exists within this MultiValueDictionary<TKey, TValue>.

Declaration
public bool Contains(TKey key, TValue value)
Parameters
Type Name Description
TKey key

The TKey of the element.

TValue value

The TValue of the element.

Returns
Type Description
Boolean

true if found; otherwise false

Exceptions
Type Condition
ArgumentNullException

key must be non-null

| Improve this Doc View Source

ContainsKey(TKey)

Determines if the given TKey exists within this MultiValueDictionary<TKey, TValue> and has at least one TValue associated with it.

Declaration
public bool ContainsKey(TKey key)
Parameters
Type Name Description
TKey key

The TKey to search the MultiValueDictionary<TKey, TValue> for

Returns
Type Description
Boolean

true if the MultiValueDictionary<TKey, TValue> contains the requested TKey; otherwise false.

Implements
IReadOnlyDictionary<TKey, TValue>.ContainsKey(TKey)
Exceptions
Type Condition
ArgumentNullException

key must be non-null

| Improve this Doc View Source

ContainsValue(TValue)

Determines if the given TValue exists within this MultiValueDictionary<TKey, TValue>.

Declaration
public bool ContainsValue(TValue value)
Parameters
Type Name Description
TValue value

A TValue to search the MultiValueDictionary<TKey, TValue> for

Returns
Type Description
Boolean

true if the MultiValueDictionary<TKey, TValue> contains the value; otherwise false

| Improve this Doc View Source

Create<TValueCollection>()

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the default IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>()where TValueCollection : ICollection<TValue>, new ()
Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

| Improve this Doc View Source

Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the default IEqualityComparer<T> for the TKey type. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable)where TValueCollection : ICollection<TValue>, new ()
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, IEqualityComparer<TKey>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the specified IEqualityComparer<T> for the TKey type. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable, IEqualityComparer<TKey> comparer)where TValueCollection : ICollection<TValue>, new ()
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, IEqualityComparer<TKey>, Func<TValueCollection>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the specified IEqualityComparer<T> for the TKey type. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable, IEqualityComparer<TKey> comparer, Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>>, Func<TValueCollection>)

Initializes a new instance of the MultiValueDictionary<TKey, TValue> class that contains elements copied from the specified IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> and uses the default IEqualityComparer<T> for the TKey type. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEnumerable<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable, Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
IEnumerable<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>> enumerable

IEnumerable to copy elements into this from

Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

ArgumentNullException

enumerable must be non-null

| Improve this Doc View Source

Create<TValueCollection>(IEqualityComparer<TKey>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the specified IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEqualityComparer<TKey> comparer)where TValueCollection : ICollection<TValue>, new ()
Parameters
Type Name Description
IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

| Improve this Doc View Source

Create<TValueCollection>(IEqualityComparer<TKey>, Func<TValueCollection>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the specified IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(IEqualityComparer<TKey> comparer, Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

| Improve this Doc View Source

Create<TValueCollection>(Func<TValueCollection>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the default initial capacity, and uses the default IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

| Improve this Doc View Source

Create<TValueCollection>(Int32)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the default IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(int capacity)where TValueCollection : ICollection<TValue>, new ()
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
ArgumentOutOfRangeException

Capacity must be >= 0

InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

| Improve this Doc View Source

Create<TValueCollection>(Int32, IEqualityComparer<TKey>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the specified IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(int capacity, IEqualityComparer<TKey> comparer)where TValueCollection : ICollection<TValue>, new ()
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

TValueCollection must not have IsReadOnly set to true by default.

ArgumentOutOfRangeException

Capacity must be >= 0

| Improve this Doc View Source

Create<TValueCollection>(Int32, IEqualityComparer<TKey>, Func<TValueCollection>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the specified IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(int capacity, IEqualityComparer<TKey> comparer, Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

IEqualityComparer<TKey> comparer

Specified comparer to use for the TKeys

Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

If comparer is set to null, then the default IEqualityComparer for TKey is used.

Exceptions
Type Condition
InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

ArgumentOutOfRangeException

Capacity must be >= 0

| Improve this Doc View Source

Create<TValueCollection>(Int32, Func<TValueCollection>)

Creates a new new instance of the MultiValueDictionary<TKey, TValue> class that is empty, has the specified initial capacity, and uses the default IEqualityComparer<T> for TKey. The internal dictionary will use instances of the TValueCollection class as its collection type.

Declaration
public static MultiValueDictionary<TKey, TValue> Create<TValueCollection>(int capacity, Func<TValueCollection> collectionFactory)where TValueCollection : ICollection<TValue>
Parameters
Type Name Description
Int32 capacity

Initial number of keys that the MultiValueDictionary<TKey, TValue> will allocate space for

Func<TValueCollection> collectionFactory

A function to create a new ICollection<T> to use in the internal dictionary store of this MultiValueDictionary<TKey, TValue>.

Returns
Type Description
MultiValueDictionary<TKey, TValue>

A new MultiValueDictionary<TKey, TValue> with the specified parameters.

Type Parameters
Name Description
TValueCollection

The collection type that this MultiValueDictionary<TKey, TValue> will contain in its internal dictionary.

Remarks

Note that TValueCollection must implement ICollection<T> in addition to being constructable through new(). The collection returned from the constructor must also not have IsReadOnly set to True by default.

Exceptions
Type Condition
ArgumentOutOfRangeException

Capacity must be >= 0

InvalidOperationException

collectionFactory must create collections with IsReadOnly set to true by default.

| Improve this Doc View Source

GetEnumerator()

Get an Enumerator over the TKey-IReadOnlyCollection<T> pairs in this MultiValueDictionary<TKey, TValue>.

Declaration
public IEnumerator<KeyValuePair<TKey, IReadOnlyCollection<TValue>>> GetEnumerator()
Returns
Type Description
IEnumerator<System.Collections.Generic.KeyValuePair<TKey, IReadOnlyCollection<TValue>>>

an Enumerator over the TKey-IReadOnlyCollection<T> pairs in this MultiValueDictionary<TKey, TValue>.

Implements
IEnumerable<T>.GetEnumerator()
| Improve this Doc View Source

Remove(TKey)

Removes every TValue associated with the given TKey from the MultiValueDictionary<TKey, TValue>.

Declaration
public bool Remove(TKey key)
Parameters
Type Name Description
TKey key

The TKey of the elements to remove

Returns
Type Description
Boolean

true if the removal was successful; otherwise false

Exceptions
Type Condition
ArgumentNullException

key is null.

| Improve this Doc View Source

Remove(TKey, TValue)

Removes the first instance (if any) of the given TKey-TValue pair from this MultiValueDictionary<TKey, TValue>.

Declaration
public bool Remove(TKey key, TValue value)
Parameters
Type Name Description
TKey key

The TKey of the element to remove

TValue value

The TValue of the element to remove

Returns
Type Description
Boolean

true if the removal was successful; otherwise false

Remarks

If the TValue being removed is the last one associated with its TKey, then that TKey will be removed from the MultiValueDictionary<TKey, TValue> and its associated IReadOnlyCollection<T> will be freed as if a call to Remove(TKey) had been made.

Exceptions
Type Condition
ArgumentNullException

key must be non-null

| Improve this Doc View Source

TryGetValue(TKey, out IReadOnlyCollection<TValue>)

Attempts to get the TValue associated with the given TKey and place it into value.

Declaration
public bool TryGetValue(TKey key, out IReadOnlyCollection<TValue> value)
Parameters
Type Name Description
TKey key

The TKey of the element to retrieve

IReadOnlyCollection<TValue> value

When this method returns, contains the TValue associated with the specified TKey if it is found; otherwise contains the default value of TValue.

Returns
Type Description
Boolean

true if the MultiValueDictionary<TKey, TValue> contains an element with the specified TKey; otherwise, false.

Implements
IReadOnlyDictionary<TKey, TValue>.TryGetValue(TKey, TValue)
Exceptions
Type Condition
ArgumentNullException

key must be non-null

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerable.GetEnumerator()

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
IEnumerator
Implements
IEnumerable.GetEnumerator()
  • Improve this Doc
  • View Source
Back to top Copyright © 2016-2017 Fubar Development Junker
Generated by DocFX