What's the best way to set all values in a C# Dictionary<string,bool>?
.net, c#, dictionary, generics
Solution
That is a reasonable approach, although I would prefer:
foreach (var key in dict.Keys.ToList())
{
dict[key] = false;
}
The call to `ToList()` makes this work, since it's pulling out and (temporarily) saving the list of keys, so the iteration works.
Problem
What's the best way to set all values in a C# Dictionary? Here is what I am doing now, but I'm sure there is a better/cleaner way to do this: ``` Dictionary<string,bool> dict = GetDictionary(); var keys = dict.Keys.ToList(); for (int i = 0; i < keys.Count; i++) { dict[keys[i]] = false; } ``` I have tried some other ways with foreach, but I had errors.