What is the best way to “reset” a Dictionary<int, bool> type of structure (set all values to true or false). Currently I’m using a ToDictionary() extension method. Is there a way to do this by reusing the current instance?
This code throws an exception:
[TestFixture]
public class Sample
{
[Test]
public void SampleTest()
{
var dictionary = new Dictionary<int, bool>{{1, false}, {2, true}, {3, false}};
foreach (var key in dictionary.Keys)
{
dictionary[key] = true;
}
Assert.That(dictionary[3], Is.True);
}
}
1 Answer