- Hashtable s = new Hashtable();
- s.Add("1","abc");
- s.Add("2", "def");
- Session["hashtable"] = s;
以上代码是错误的,没有进行类型转换,因为session为对象类。要转换。
- Hashtable ht = (Hashtable)Session["HT"];
- Response.Write(ht["A"].ToString()+"--"+ht["B"].ToString());or
- Hashtable ht = (Hashtable)Session["HT"];
- foreach (DictionaryEntry de in ht)
- {
- Response.Write(de.Key.ToString() + " value is "+de.Value.ToString());
- }