GOA - System.Collections.DictionaryBase

DictionaryBase Class


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

Definition

public abstract class DictionaryBase: Object, IDictionary

Members Table

MethodDescription
AddWhen implemented by a class, adds an element with the provided key and value to the IDictionary. (Inherited from IDictionary)
ClearClears the contents of the DictionaryBase instance.
ContainsWhen implemented by a class, determines whether the IDictionary contains an element with the specified key. (Inherited from IDictionary)
CopyToCopies the DictionaryBase elements to a one-dimensional Array at the specified index.
DictionaryBaseInitializes a new instance of DictionaryBase.
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetEnumeratorOverloaded. Returns an enumerator that can iterate through the DictionaryBase.
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
OnClearPerforms additional custom processes before clearing the contents of the DictionaryBase instance.
OnClearCompletePerforms additional custom processes after clearing the contents of the DictionaryBase instance.
OnGetGets the element with the specified key and value in the DictionaryBase instance.
OnInsertPerforms additional custom processes before inserting a new element into the DictionaryBase instance.
OnInsertCompletePerforms additional custom processes after inserting a new element into the DictionaryBase instance.
OnRemovePerforms additional custom processes before removing an element from the DictionaryBase instance.
OnRemoveCompletePerforms additional custom processes after removing an element from the DictionaryBase instance.
OnSetPerforms additional custom processes before setting a value in the DictionaryBase instance.
OnSetCompletePerforms additional custom processes after setting a value in the DictionaryBase instance.
OnValidatePerforms additional custom processes when validating the element with the specified key and value.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
RemoveWhen implemented by a class, removes the element with the specified key from the IDictionary. (Inherited from IDictionary)
System.Collections.IDictionary.AddAdds an element with the provided key and value to the DictionaryBase.
System.Collections.IDictionary.ContainsDetermines whether the DictionaryBase contains a specific key.
System.Collections.IDictionary.RemoveRemoves the element with the specified key from the DictionaryBase.
System.Collections.IDictionary.this[]Gets or sets the element with the specified key.
System.Collections.IEnumerable.GetEnumeratorReturns an IEnumerator that can iterate through the DictionaryBase.
ToStringReturns a String that represents the current Object. (Inherited from Object)
this[]When implemented by a class, gets or sets the element with the specified key. (Inherited from IDictionary)
PropertyDescription
CountGets the number of pairs elements contained in the DictionaryBase instance.
DictionaryGets an IDictionary containing the list of elements in the DictionaryBase instance.
InnerHashtableGets a Hashtable containing the list of elements in the DictionaryBase instance.
IsFixedSizeWhen implemented by a class, gets a value indicating whether the IDictionary has a fixed size. (Inherited from IDictionary)
IsReadOnlyWhen implemented by a class, gets a value indicating whether the IDictionary is read-only. (Inherited from IDictionary)
IsSynchronizedWhen implemented by a class, gets a value indicating whether access to the ICollection is synchronized. (Inherited from ICollection)
KeysWhen implemented by a class, gets an ICollection containing the keys of the IDictionary. (Inherited from IDictionary)
SyncRootWhen implemented by a class, gets an object that can be used to synchronize access to the ICollection. (Inherited from ICollection)
System.Collections.ICollection.IsSynchronizedGets a value indicating whether access to the DictionaryBase is synchronized.
System.Collections.ICollection.SyncRootGets an object that can be used to synchronize access to the DictionaryBase.
System.Collections.IDictionary.IsFixedSizeGets a value indicating whether the DictionaryBase has a fixed size.
System.Collections.IDictionary.IsReadOnlyGets a value indicating whether the DictionaryBase is read-only.
System.Collections.IDictionary.KeysGets an ICollection containing the keys of the DictionaryBase.
System.Collections.IDictionary.ValuesGets an ICollection containing the values in the DictionaryBase.
ValuesWhen implemented by a class, gets an ICollection containing the values in the IDictionary. (Inherited from IDictionary)

Inheritance Hierarchy

Object
DictionaryBase

Examples

// This examples shows how to implement a DictionaryBase.

// It shows also some properties and method of the DictionaryBase class.

 

using System;

using System.Collections;

using System.Diagnostics;

 

public class SampleDictionaryBase

{

     static void Main()

     {

          // Creates and initializes a new DictionaryBase.

          MyDictionary myDict = new MyDictionary();

 

          // Adds elements to the collection.

          myDict.Add( 1, "a" );

          myDict.Add( 2, "ab" );

          myDict.Add( 3, "abc" );

          myDict.Add( 4, "abcd" );

          myDict.Add( 5, "abcde" );

 

          // Displays the contents of the collection.

          Debug.WriteLine("Initial contents of the collection:");

          DisplayValues3(myDict);

 

          // Searches the collection with Contains.

          Debug.WriteLine(@"Contains ""3"":" +myDict.Contains( 3 ).ToString());

          Debug.WriteLine(@"Contains ""12"":" +myDict.Contains( 12 ).ToString());

 

          // Creates and displays the content of an array.

          int[] myIntArray = new int[5] ;

          Debug.Write("\nContents of an array of int:");

          DisplayArrayValues(myIntArray);

 

          // Copies the keys of the collection to the array of int.

          myDict.Keys.CopyTo(myIntArray,0);

          Debug.Write("\n\nContents of the array after copying the keys of the collection in it:");

          DisplayArrayValues(myIntArray);

 

          // Removes an element from the collection.

          myDict.Remove( 2 );

          Debug.WriteLine("\n\n"+@"Contents of the collection after removing ""2"":");

          DisplayValues3(myDict);

     }

 

     // Displays values using Keys property and the this[] method.

     public static void DisplayValues( MyDictionary myDictionary )

     {

          ICollection myKeys = myDictionary.Keys;

          foreach ( int k in myKeys )

               Debug.WriteLine("\t"+k+":"+myDictionary[k].ToString());

     }

 

     // Displays values using an enumerator.

     public static void DisplayValues2( MyDictionary myDictionary )

     {

          DictionaryEntry myDE;

          System.Collections.IEnumerator myEnumerator = myDictionary.GetEnumerator();

          while ( myEnumerator.MoveNext() )

               if ( myEnumerator.Current != null )

                    myDE = (DictionaryEntry) myEnumerator.Current;

                    Debug.WriteLine("\t"+myDE.Key.ToString()+":"+myDE.Value.ToString());

     }

 

     // Displays values using the foreach statement.

     public static void DisplayValues3 ( MyDictionary myDictionary)

     {

          foreach ( DictionaryEntry myDE in myDictionary )

               Debug.WriteLine("\t"+myDE.Key.ToString()+":"+myDE.Value.ToString());

     }

 

     // Displays the values of an array.

     public static void DisplayArrayValues ( Array array )

     {

          for ( int i = 0; i < array.Length; i++ )

          {

               Debug.Write(array.GetValue(i)+" ");

          }

     }

}

 

public class MyDictionary : DictionaryBase

{

     public string this[ int key ]

     {

          get

          {

               return( (string) Dictionary[key] );

          }

          set

          {

               Dictionary[key] = value;

          }

     }

 

     public ICollection Keys

     {

          get

          {

               return( Dictionary.Keys );

          }

     }

 

     public ICollection Values

     {

          get

          {

               return( Dictionary.Values );

          }

     }

 

     public void Add( int key, String value )

     {

          Dictionary.Add( key, value );

     }

 

     public bool Contains( int key )

     {

          return( Dictionary.Contains( key ) );

     }

 

     public void Remove( int key )

     {

          Dictionary.Remove( key );

     }

 

     protected override void OnInsert( Object key, Object value )

     {

          // Insert additional code to be executed only when inserting values.

     }

 

     protected override void OnRemove( Object key, Object value )

     {

          // Insert additional code to be executed only when removing values.

     }

 

     protected override void OnSet( Object key, Object oldValue, Object newValue )

     {

          // Insert additional code to be executed only when setting values.

     }

}

 

/*

 

The output of the sample.

 

Initial contents of the collection:

     5:abcde

     1:a

     3:abc

     2:ab

     4:abcd

Contains "3":True

Contains "12":False

 

Contents of an array of int:0 0 0 0 0

Contents of the array after copying the keys of the collection in it:4 2 3 5 1

 

Contents of the collection after removing 2:

     5:abcde

     1:a

     3:abc

     4:abcd

 

*/

Class Information

NamespaceSystem.Collections
Flash Librarycorlib.scl
Flash Library Version2.0.0.2466
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.