How do I increase a number by one with a value stored in dictionary? C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I increase a number by one with a value stored in dictionary? C#

//GETS CUSTOMERSNAME static Dictionary<string, int> _Names = new Dictionary<string, int> { {"LIAM O'BRIEN", 29}, {"CIARAN O'BRIEN", 30}, }; public static void RecordData(string CustomerNameCheck,int NumberOfBookings) { try { _Names.Add(CustomerNameCheck, NumberOfBookings); } catch (ArgumentException) { Console.WriteLine("Value found!"); Console.ReadKey(); } } Just started to learn to program for the first time and I am currently trying to build a cinema app. {"LIAM O'BRIEN", 29}, 29 is the number of bookings made, I want to increase that number by one once the customer "LIAM O'BRIEN" completes another booking. Any suggestions?

14th Mar 2023, 8:44 PM
Liam
1 Answer
+ 7
Simplest way: _Names["LIAM O'BRIEN"] = _Names["LIAM O'BRIEN"] + 1; More detail: https://code-maze.com/csharp-update-the-value-stored-in-a-dictionary/
14th Mar 2023, 8:49 PM
Tibor Santa
Tibor Santa - avatar