这是用ArrayList的一段程序,应该用HashTable也一样的,你试试。其中CCode是我自定义的类,myCodeInfo是我自定义的集合,你不用管,oCodesList是ArrayList类型的,你改成Hashtable应该也可以。CCodes oCodes=new CCodes();
CCodesInfo myCodeInfo=CCodesInfo.GetClass(); System.Collections.IEnumerator myEnumerator =myCodeInfo.oCodesList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
if (((CCodes)myEnumerator.Current).sCodeTypeID==CodeTypeID)
{
oCodes=(CCodes)myEnumerator.Current;
}
}
return oCodes;

解决方案 »

  1.   

    下列示例说明如何创建和初始化 Hashtable,以及如何打印出其键和值。[C#] 
    using System;
    using System.Collections;
    public class SamplesHashtable  {   public static void Main()  {      // Creates and initializes a new Hashtable.
          Hashtable myHT = new Hashtable();
          myHT.Add("First", "Hello");
          myHT.Add("Second", "World");
          myHT.Add("Third", "!");      // Displays the properties and values of the Hashtable.
          Console.WriteLine( "myHT" );
          Console.WriteLine( "  Count:    {0}", myHT.Count );
          Console.WriteLine( "  Keys and Values:" );
          PrintKeysAndValues( myHT );
       }
       public static void PrintKeysAndValues( Hashtable myList )  {
          IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
          Console.WriteLine( "\t-KEY-\t-VALUE-" );
          while ( myEnumerator.MoveNext() )
             Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value);
          Console.WriteLine();
       }
    }
    /* 
    This code produces the following output.myHT
      Count:    3
      Keys and Values:
        -KEY-    -VALUE-
        Third:    !
        Second:    World
        First:    Hello
    */.NET Framework示例
      

  2.   

    声明
    Hashtable temp=new Hashtable();添加
    temp.Add(1,"test")
    ...
    ...取得
    string tempstr=temp[1];
    mouse
      

  3.   

    有点错误声明
    Hashtable temp=new Hashtable();添加
    temp.Add(1,"test")
    ...
    ...取得
    string tempstr=(string)temp[1];mouse
      

  4.   

    HashTable可以使用任意对象类型作为key,也可以使用任意对象类型作为value。