Export (0) Print
Expand All

DictionaryBase Class

Provides the abstract base class for a strongly typed collection of key/value pairs.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

[<AbstractClass>]
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type DictionaryBase =  
    class 
        interface IDictionary 
        interface ICollection 
        interface IEnumerable 
    end

The DictionaryBase type exposes the following members.

  NameDescription
Protected methodDictionaryBaseInitializes a new instance of the DictionaryBase class.
Top

  NameDescription
Public propertyCountGets the number of elements contained in the DictionaryBase instance.
Protected propertyDictionaryGets the list of elements contained in the DictionaryBase instance.
Protected propertyInnerHashtableGets the list of elements contained in the DictionaryBase instance.
Top

  NameDescription
Public methodClearClears the contents of the DictionaryBase instance.
Public methodCopyToCopies the DictionaryBase elements to a one-dimensional Array at the specified index.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an IDictionaryEnumerator that iterates through the DictionaryBase instance.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnClearPerforms additional custom processes before clearing the contents of the DictionaryBase instance.
Protected methodOnClearCompletePerforms additional custom processes after clearing the contents of the DictionaryBase instance.
Protected methodOnGetGets the element with the specified key and value in the DictionaryBase instance.
Protected methodOnInsertPerforms additional custom processes before inserting a new element into the DictionaryBase instance.
Protected methodOnInsertCompletePerforms additional custom processes after inserting a new element into the DictionaryBase instance.
Protected methodOnRemovePerforms additional custom processes before removing an element from the DictionaryBase instance.
Protected methodOnRemoveCompletePerforms additional custom processes after removing an element from the DictionaryBase instance.
Protected methodOnSetPerforms additional custom processes before setting a value in the DictionaryBase instance.
Protected methodOnSetCompletePerforms additional custom processes after setting a value in the DictionaryBase instance.
Protected methodOnValidatePerforms additional custom processes when validating the element with the specified key and value.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodCast(TResult)()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodCast(TResult)()Overloaded. (Defined by Enumerable.)
Public Extension MethodOfType(TResult)()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodOfType(TResult)()Overloaded. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value indicating whether access to a DictionaryBase object is synchronized (thread safe).
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to a DictionaryBase object.
Explicit interface implemetationPrivate methodIDictionary.AddAdds an element with the specified key and value into the DictionaryBase.
Explicit interface implemetationPrivate methodIDictionary.ContainsDetermines whether the DictionaryBase contains a specific key.
Explicit interface implemetationPrivate propertyIDictionary.IsFixedSizeGets a value indicating whether a DictionaryBase object has a fixed size.
Explicit interface implemetationPrivate propertyIDictionary.IsReadOnlyGets a value indicating whether a DictionaryBase object is read-only.
Explicit interface implemetationPrivate propertyIDictionary.ItemGets or sets the value associated with the specified key.
Explicit interface implemetationPrivate propertyIDictionary.KeysGets an ICollection object containing the keys in the DictionaryBase object.
Explicit interface implemetationPrivate methodIDictionary.RemoveRemoves the element with the specified key from the DictionaryBase.
Explicit interface implemetationPrivate propertyIDictionary.ValuesGets an ICollection object containing the values in the DictionaryBase object.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an IEnumerator that iterates through the DictionaryBase.
Top

The foreach statement of the C# language (for each in Visual Basic) returns an object of the type of the elements in the collection. Since each element of the DictionaryBase is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry.

The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

NoteNote

Because keys can be inherited and their behavior changed, their absolute uniqueness cannot be guaranteed by comparisons using the Equals method.

Notes to Implementers

This base class is provided to make it easier for implementers to create a strongly typed custom collection. Implementers are encouraged to extend this base class instead of creating their own.

Members of this base class are protected and are intended to be used through a derived class only.

The following code example implements the DictionaryBase class and uses that implementation to create a dictionary of String keys and values that have a Length of 5 characters or less.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

This implementation does not provide a synchronized (thread-safe) wrapper for a DictionaryBase, but derived classes can create their own synchronized versions of the DictionaryBase using the SyncRoot property.

Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft