How to delete entries from a dictionary using the value

后端 未结 5 886
广开言路
广开言路 2021-01-06 10:48

I have a dictionary collection as bleow:

mydic.addvalue(key1, val1)
mydic.addvalue(key2, val1)
mydic.addvalue(key3, val1)
mydic.addvalue(key4, val2)
mydic.ad         


        
5条回答
  •  有刺的猬
    2021-01-06 11:39

    The answer it's old but this is how I do the same thing without create another Dictionary.

    foreach (KeyValuePair x in MyDic) {
    
      if (x.Value == "val1")) 
      {  MyDic.Remove(x.Key); } 
    }
    

提交回复
热议问题