我有字典(buzzCompaignsPerUserIntersets)的問題,我有字典(key = stringand value = ICollection),我想從每個鍵的值中刪除,比較至極驗證條件這裏是代碼誰我用:從字典中刪除項目,同時迭代它
buzzCompaignsPerUserIntersets = Dictionary<string, ICollection<Buzzcompaign> ;
foreach(var dic_compaign in buzzCompaignsPerUserIntersets)
{
var listCompaign = buzzCompaignsPerUserIntersets[dic_compaign.Key];
for (int i = 0; i < listCompaign.Count(); i++)
{
if (listCompaign.ElementAt(i).MayaMembership.MayaProfile.MayaProfileId == profile_id)
buzzCompaignsPerUserIntersets[dic_compaign.Key].Remove(listCompaign.ElementAt(i));
}
}
與此代碼我碰到了奇怪的結果,因爲我遍歷一個字典至極,我從他們刪除元素,你有什麼建議
謝謝艾哈邁德先生,這一整天都在我身邊,這很有趣! – ucef 2012-07-06 19:33:46