GOA - System.Collections.Specialized.NameHashtable

NameHashtable Class


Provides the abstract base class for a collection of associated String keys and Object values that are organized based on the hash code of the key. This class cannot be inherited.

Definition

public sealed class NameHashtable: Object, IDictionary

Members Table

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

Inheritance Hierarchy

Object
NameHashtable

Examples

// This example shows how to create and initialize a NameHashtable.

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

 

using System;

using System.Diagnostics;

using System.Collections;

using System.Collections.Specialized;

 

public class SampleNameHashtable

{

     static void Main()

     {

          // Creates and initializes a new NameHashtable.

          NameHashtable myNhash= new NameHashtable();

 

          // Adds elements to the NameHashtable.

          myNhash.Add( "Apple", 1.49 );

          myNhash.Add( "Banana", 1.29 );

          myNhash.Add( "Lemon", 1.49 );

          myNhash.Add( "Strawberry", 1.29 );

          myNhash.Add( "Orange", 0.89 );

          myNhash.Add( "Coconut", 0.99 );

 

          // Displays the contents of the NameHashtable.

          Debug.WriteLine("Initial contents of the NameHashtable(key:value):");

          DisplayValues(myNhash);

 

          // Searches the NameHashtable with Contains method.

          bool contain = myNhash.Contains("Coconut");

          Debug.WriteLine("\n"+@"Contains ""Coconut"":" +contain.ToString());

 

          // Removes an element of the NameHashtable.

          myNhash.Remove("Coconut");

          Debug.WriteLine("\n"+@"Contents of the NameHashtable after removing the ""Coconut"" key element(key:value):");

          DisplayValues2(myNhash);

 

          // Creates and initialize an array of string.

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

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

          DisplayArrayValues(myStringArray);

 

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

          myNhash.Keys.CopyTo(myStringArray, 0);

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

          DisplayArrayValues(myStringArray);

 

          // Set the value of one element of the NameHashtable.

          myNhash["Apple"]="test";

          Debug.WriteLine("\n\n"+@"Contents of the NameHashtable after setting the ""Apple"" key element to ""test"":");

          DisplayValues3(myNhash);

     }

 

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

     public static void DisplayValues( NameHashtable myNameHashtable )

     {

          ICollection myKeys = myNameHashtable.Keys;

          foreach ( string k in myKeys )

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

     }

 

     // Displays values using an enumerator.

     public static void DisplayValues2( NameHashtable myNameHashtable )

     {

          DictionaryEntry myDE;

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

     {

          foreach ( DictionaryEntry myDE in myNameHashtable )

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

     }

 

     // 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 NameHashtable(key:value):

     Coconut:0.99

     Orange:0.89

     Strawberry:1.29

     Lemon:1.49

     Banana:1.29

     Apple:1.49

Contains "Coconut":True

 

Contents of the NameHashtable after removing the "Coconut" key element(key:value):

     Orange:0.89

     Strawberry:1.29

     Lemon:1.49

     Banana:1.29

     Apple:1.49

 

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

Contents of the array after copying the keys of the NameHashtable in it:Orange Strawberry Lemon Banana Apple pqr stu

 

Contents of the NameHashtable after setting the "Apple" key element to "test":

     Orange:0.89

     Strawberry:1.29

     Lemon:1.49

     Banana:1.29

     Apple:test

 

*/

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.