我有一個字典,我把它放在會話中,並在每個按鈕上單擊我需要執行一些操作。通過字典集循環搜索一個鍵並增加值
itemColl = new Dictionary<int, int>();
我要搜索,我在一個會話變量保持的關鍵,如果那麼關鍵存在我想以1爲相應的鍵,我怎麼能實現這一目標,以增加價值。
我想它,如下所示:
if (Session["CurrCatId"] != null)
{
CurrCatId = (int)(Session["CurrCatId"]);
// this is the first time, next time i will fetch from session
// and want to search the currcatid and increase the value from
// corresponding key by 1.
itemColl = new Dictionary<int, int>();
itemColl.Add(CurrCatId, 1);
Session["itemColl"] = itemColl;
}
什麼是itemCol1,這個語句爲itemCol1 [CurrCatId] ++; – NoviceToDotNet
@NoviceToDotNet,而'itemColl [CurrCatId] ++'爲你提供這個'如果鍵存在,那麼我想增加1的值。 –
我想增加一個密鑰的價值,如果在會話中存在.. – NoviceToDotNet