System.Collections.IDictionary Interface

public interface IDictionary : ICollection, IEnumerable

Base Types

This type implements ICollection and IEnumerable.

Assembly

mscorlib

Library

BCL

Summary

Implemented by classes that support collections of associated keys and values (i.e. dictionaries).

Description

[Note: Each key-value pair must have a unique non-null key, but the value of an association can be any object reference, including a null reference. The IDictionary interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.

IDictionary implementations fall into three categories: read-only, fixed-size, variable-size. A read-only implementation cannot be modified. A fixed-size implementation does not allow the addition or removal of elements, but it allows the modification of existing elements. A variable-size implementation allows the addition, removal and modification of elements.

]

Attributes

DefaultMemberAttribute("Item")

See Also

System.Collections Namespace

Members

IDictionary Methods

IDictionary.Add Method
IDictionary.Clear Method
IDictionary.Contains Method
IDictionary.GetEnumerator Method
IDictionary.Remove Method

IDictionary Properties

IDictionary.IsFixedSize Property
IDictionary.IsReadOnly Property
IDictionary.Item Property
IDictionary.Keys Property
IDictionary.Values Property


IDictionary.Add Method

void Add(object key, object value);

Summary

Adds an entry with the provided key and value to the current instance.

Parameters

key
The Object to use as the key of the entry to add.
value
The Object to use as the value of the entry to add.

Exceptions

Exception TypeCondition
ArgumentNullExceptionkey is null .

ArgumentException An entry with the same key already exists in the current instance.

NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

If the specified key already exists in the current instance, this method throws a ArgumentException exception but does not modify the associated value.

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Clear Method

void Clear();

Summary

Removes all key and value pairs from the current instance.

Exceptions

Exception TypeCondition
NotSupportedExceptionThe IDictionary is read-only.

Description

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Contains Method

bool Contains(object key);

Summary

Determines whether the current instance contains an entry with the specified key.

Parameters

key
The key to locate in the IDictionary.

Return Value

true if the IDictionary contains an entry with the key; otherwise, false .

Exceptions

Exception TypeCondition
ArgumentNullExceptionkey is null .

Description

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.GetEnumerator Method

IDictionaryEnumerator GetEnumerator();

Summary

Returns a IDictionaryEnumerator for the current instance.

Return Value

A IDictionaryEnumerator for the current instance.

Description

[Note: For detailed information regarding the use of an enumerator, see IEnumerator.]

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Remove Method

void Remove(object key);

Summary

Removes the entry with the specified key from the current instance.

Parameters

key
The key of the entry to remove.

Exceptions

Exception TypeCondition
ArgumentNullExceptionkey is null .
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

[Behaviors: If key is not found in the current instance, no exception is thrown and the current instance remains unchanged.

]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.IsFixedSize Property

bool IsFixedSize { get; }

Summary

Gets a value indicating whether the current instance has a fixed size.

Property Value

true if the current instance has a fixed size; otherwise, false .

Description

This property is read-only.

[Note: A collection with a fixed size does not allow the addition or removal of elements, but does allow the modification of existing elements.]

[Behaviors: As described above.]

[Default: The default of this property is false .]

[Overrides: Override this method, setting the value as true , to prevent the addition and removal of the elements in the current instance.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.IsReadOnly Property

bool IsReadOnly { get; }

Summary

Gets a value indicating whether the current instance is read-only.

Property Value

true if the current instance is read-only; otherwise, false .

Description

This property is read-only.

[Note: A collection that is read-only does not allow the addition, removal, or modification of elements.]

[Behaviors: As described above.]

[Default: The default of this property is false .]

[Overrides: Override this method, setting the value as true , to prevent the addition, removal, and modification of the elements in the current instance.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Item Property

object this[object key] { get; set; }

Summary

Gets or sets the element in the current instance that is associated with the specified key.

Parameters

key
The key of the element to get or set.

Property Value

The element with the specified key.

Exceptions

Exception TypeCondition
ArgumentNullExceptionkey is null .

NotSupportedExceptionThe property is set and the current instance is read-only.

The property is set, key does not exist in the collection, and the current instance has a fixed size.

Description

[Note: This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[index].]

[Behaviors: When setting this property, if the specified key already exists in the current instance, the value is required to be replaced; otherwise, a new element is required to be created.

]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Keys Property

ICollection Keys { get; }

Summary

Gets a ICollection containing the keys of the current instance.

Property Value

A ICollection containing the keys of the current instance.

Description

This property is read-only.

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace

IDictionary.Values Property

ICollection Values { get; }

Summary

Gets a ICollection containing the values in the current instance.

Property Value

A ICollection containing the values in the current instance.

Description

This property is read-only.

[Behaviors: As described above.]

See Also

System.Collections.IDictionary Interface, System.Collections Namespace