object product_id = e.CommandArgument;
            Response.Write(product_id);
            Hashtable ht = (Hashtable)Session["car"];
            foreach (DictionaryEntry de in ht) //ht为一个Hashtable实例
            {
                Response.Write(de.Key);
            }
            if (ht.Contains(product_id))
            {
                Response.Write("true");
            }
            else
            {
                Response.Write("false");
            }
            //ht.Remove(product_id);
我写了上面的程序, Response.Write(product_id)与 Response.Write(de.Key)输出地值是一样的,所以我推断执行 if (ht.Contains(product_id))输出的应该是true,但是实际上输出是false,这是为什么啊?
我是菜鸟,请大侠们帮帮忙,在线等!先谢了!

解决方案 »

  1.   

    HT记录是一个对象,这个对象有Key,Value,你应该用ht.ContainsKey(product_id)。
      

  2.   

     object product_id = e.CommandArgument;
            Response.Write(product_id);
            Hashtable ht = (Hashtable)Session["car"];
            foreach (DictionaryEntry de in ht) //ht为一个Hashtable实例
            {
                Response.Write(de.Key);
            }
            if (ht.ContainsKey(product_id))
            {
                Response.Write("true");
            }
            else
            {
                Response.Write("false");
            }
      

  3.   

    你那是de.Key
      

  4.   

    我试了,还是不行!返回的结果仍是false!