I am trying to update value in c# dictionary object if value is something.
Dictionary<string, int> Section = new Dictionary<string, int>()
{
{"a", 1},
{"b", 0},
{"c", 2},
{"d", 0},
{"e", 0},
{"f", 0},
};
- I want to loop through Section object and if value= 2 i want to set it to 1
- I want to set the value = 1 from 4th element till end.(i.e, from “d” to “f”)
Thanks,
Praveen
I have tried,
foreach(var item in Section)
{
if(item.value == 2)
{
item.value == 1;
}
}
You can look through the Dictionary items, and change the value as needed.
This could be something like:
Realize that, once you put the values in a dictionary, they lose all ordering. A Dictionary is inherently an unordered collection.