0

Help please

Some one can help me how modify values from a dictionary, in the final exam asked me change the discount but i can use the value to do operations so please help

23rd Feb 2022, 5:47 AM
Mario Legoguy
Mario Legoguy - avatar
6 Antworten
+ 1
My solution was successful by looping through the keys, retrieving the values, temporarily calculating the discounted value, then printing the key with the temporary value. I didn't need to update the dictionary values.
23rd Feb 2022, 6:42 AM
Brian
Brian - avatar
+ 1
I used a foreach statement to loop through the keys. foreach (string menu in coffee.Keys.ToArray) Then I used the loop index (menu) to look up the value in the dictionary. coffee[menu]
23rd Feb 2022, 8:08 AM
Brian
Brian - avatar
+ 1
If you want only the values, you can use the .Values property. https://xwww.geeksforgeeks.org/c-sharp-dictionary-values-property/
23rd Feb 2022, 3:40 PM
Brian
Brian - avatar
0
How can i get the values?
23rd Feb 2022, 6:44 AM
Mario Legoguy
Mario Legoguy - avatar
0
I did not understand exactly what you meant. However, if you want to change the value of the dictionary, use this method Example myDictionary[myKey] = myNewValue
23rd Feb 2022, 3:11 PM
hossein B
hossein B - avatar
0
Ok, but It you can use the value for operations?
23rd Feb 2022, 3:14 PM
Mario Legoguy
Mario Legoguy - avatar