GOA - System.Collections.Specialized.ListDictionary

ListDictionary Class


Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.

Definition

public class ListDictionary: Object, IDictionary, ICollection, IEnumerable

Members Table

MethodDescription
AddAdds an entry with the specified key and value into the ListDictionary.
ClearRemoves all entries from the ListDictionary.
ContainsDetermines whether the ListDictionary contains a specific key.
CopyToCopies the ListDictionary entries to a one-dimensional Array instance at the specified index.
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetEnumeratorOverloaded. (Inherited from IEnumerable)
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)
ListDictionaryOverloaded. Initializes a new instance of ListDictionary.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
RemoveRemoves the entry with the specified key from the ListDictionary.
System.Collections.IEnumerable.GetEnumeratorReturns an IEnumerator that can iterate through a ListDictionary.
ToStringReturns a String that represents the current Object. (Inherited from Object)
this[]Gets or sets the value associated with the specified key.
PropertyDescription
CountGets the number of key-and-value pairs contained in the ListDictionary.
IsFixedSizeGets a value indicating whether the ListDictionary has a fixed size.
IsReadOnlyGets a value indicating whether the ListDictionary is read-only.
IsSynchronizedGets a value indicating whether access to the the ListDictionary is synchronized.
KeysGets an ICollection containing the keys in the ListDictionary.
SyncRootGets an object that can be used to synchronize access to the ListDictionary.
ValuesGets an ICollection containing the values in the ListDictionary.

Inheritance Hierarchy

Object
ListDictionary

Examples

// This examples shows how to create and initialize a ListDictionary.

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

 

using System;

using System.Diagnostics;

using System.Collections;

using System.Collections.Specialized;

 

public class SampleListDictionary

{

     static void Main()

     {

          // Creates and initializes a new ListDictionary.

          ListDictionary myLD = new ListDictionary();

 

          // Adds elements to the ListDictionary.

          myLD.Add( "Hello", 0.99);

          myLD.Add( "This", 1.49 );

          myLD.Add( "is", 1.29 );

          myLD.Add( "a", 1.69 );

          myLD.Add( "Test", 1.29 );

          myLD.Add( "!", 0.89 );

 

          // Displays the contents of the ListDictionary.

          Debug.WriteLine("\nInitial contents of the List dictionary(key:value):");

          DisplayValues4(myLD);

 

          // Searches the ListDictionary with Contains method.

          Debug.WriteLine("\n"+@"Contains ""Hello"":" +myLD.Contains("Hello"));

 

          // Removes an element of the list dictionary.

          myLD.Remove("This");

          Debug.WriteLine("\n"+@"Contents of the List dictionary after removing the element having for key ""This"" (key:value):");

          DisplayValues(myLD);

 

          // Creates and initialize an arry of string.

          string[] myStringArray = new string[6] {"abc", "def", "ghi", "jkl", "mno","pqr"};

          Debug.Write("\nInitial contents of an array of string:");

          DisplayArrayValues(myStringArray);

 

          // Copies the keys of the ListDictionary to the array.

          myLD.Keys.CopyTo(myStringArray,0);

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

          DisplayArrayValues(myStringArray);

     }

 

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

     public static void DisplayValues( ListDictionary myListDictionary )

     {

          ICollection myKeys = myListDictionary.Keys;

          foreach ( string k in myKeys )

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

     }

 

     // Displays values using an enumerator.

     public static void DisplayValues2( ListDictionary myListDictionary )

     {

          DictionaryEntry myDE;

          System.Collections.IEnumerator myEnumerator = myListDictionary.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 ( ListDictionary myListDictionary)

     {

          foreach ( DictionaryEntry myDE in myListDictionary )

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

     }

 

     // Uses the Keys, Values, Count properties and this[] method.

     public static void DisplayValues4( ListDictionary myListDictionary )

     {

          string[] myKeys = new string[myListDictionary.Count];

          myListDictionary.Keys.CopyTo( myKeys, 0 );

 

          double[] myValues = new double[myListDictionary.Count];

          myListDictionary.Values.CopyTo( myValues, 0);

 

          for ( int i = 0; i < myListDictionary.Count; i++ )

               Debug.WriteLine( "\t"+myKeys[i]+":"+myValues[i] );

     }

 

     // Displays values of an array.

     public static void DisplayArrayValues ( Array array )

     {

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

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

     }

}

 

 

/*

 

The output of the sample.

 

Initial contents of the List dictionary(key:value):

     Hello:0.99

     This:1.49

     is:1.29

     a:1.69

     Test:1.29

     !:0.89

Contains "Hello":True

 

Contents of the List dictionary after removing the element having for key "This"(key:value):

     Hello:0.99

     is:1.29

     a:1.69

     Test:1.29

     !:0.89

 

Initial contents of an array of string:abc def ghi jkl mno pqr

Contents of the array after copying the keys of the ListDictionary in it:Hello is a Test ! pqr

 

*/

Class Information

NamespaceSystem.Collections.Specialized
Flash LibrarySystem.scl
Flash Library Version2.0.0.1308
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.