Hashtable ht = (Hashtable)ViewState["htL"];
        DataTable dt = (DataTable)ViewState["dtL"];

        if (ht.IsNotNullOrEmpty() && dt.IsNotNullOrEmpty())
        {
            foreach (DictionaryEntry de in ht)
            {
                foreach (DataRow dr in dt.Rows)
                {

       //执行操作
                    if (de.Key.ToInt() != dr["accountId"].ToInt())
                    {

 

                    }
                }
            }
        }

 

Hashtable 是字典集合,需要用DictionaryEntry接收

DataTable 是数据库表行的集合,需要用DataRow接收

上面是用foreach遍历,相对for速度相对来说会快些。(在数据量大的情况,或者整个网站,尽量用foreach)

-------------------------------------------------------

 for (int i = 0; i < ht.Count; i++)
        {
            for (int j = 0; j < dt.Rows.Count; j++)
            {
               
            }
        }

这是for遍历,速度会比foreach慢些。

posted on 2010-12-22 09:04  仰天長嘯  阅读(592)  评论(0编辑  收藏  举报
2222222222