using System;
public class Class1
{
static void Main()
{
System.Collections.Hashtable ht = new ystem.Collections.Hashtable();
System.Collections.ArrayList al2 = new System.Collections.ArrayList();
while(true)
{
string str = Console.ReadLine();

if(str.Equals("exit"))System.Environment.Exit(1);
string [] s = str.Split(' ');
if(ht.ContainsKey(s[0]))
{
System.Collections.ArrayList al = (System.Collections.ArrayList) ht[s[0]] as System.Collections.ArrayList;
al.Add(s[1]);
ht.Remove(s[0]);
ht.Add(s[0],al);
}
else
{
ht.Add(s[0],al2.Add(s[1]));
}
System.Collections.IDictionaryEnumerator ide = ht.GetEnumerator();
while(ide.MoveNext())

System.Collections.ArrayList al = (System.Collections.ArrayList)ide.Value as System.Collections.ArrayList;
Console.WriteLine("ht[key]={0}=======================>",ide.Key);
for(int i=0;i<al.Count;i++)
{
Console.WriteLine("ht[key]={0},ht[value]={1}",ide.Key,al[i]);
}

}
}
}

说明:hashtable[key=string][value=ArrayList]
我想打印key下的所有Value元素,而Value放的是ArrayList.
所以Value需要转换一下.我用 as 的方式转换报错! 
 
未处理的异常: System.InvalidCastException: 指定的转换无效。