简体   繁体   English

如何更新字典中的所有值<string, bool></string,>

[英]How to update all the values in a Dictionary<string, bool>

I am using c# vs2005 compact framework.我正在使用 c# vs2005 紧凑框架。

I need to update all the values in the dictionary to false.我需要将字典中的所有值更新为 false。

foreach (string key in parameterDictionary.Keys.ToList())
  parameterDictionary[key] = false;

".ToList() is not available" in compactframework. compactframework 中的“.ToList() 不可用” How can i loop and update.我如何循环和更新。

Can any one suggest the way to update all the values in a dictionary.任何人都可以建议更新字典中所有值的方法。

I don't know if the compact framework is different, but you can't modify the dictionary KeyValuePair directly in a ForEach.我不知道紧凑框架是否不同,但是您不能直接在 ForEach 中修改字典 KeyValuePair。 You have to copy a list of keys first:您必须先复制一个键列表:

List<string> keys = new List<string>(parameterDictionary.Keys);
foreach (string key in keys)
  parameterDictionary[key] = false;  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM