So I have this Hashtable
Hashtable Months = new Hashtable();
Months.Add(0, "JANUARY");
Months.Add(1, "FEBRUARY");
Months.Add(2, "MARCH");
Months.Add(3, "APRIL");
Months.Add(4, "MAY");
Months.Add(5, "JUNE");
Months.Add(6, "JULY");
Months.Add(7, "AUGUST");
Months.Add(8, "SEPTEMBER");
Months.Add(9, "OCTOBER");
Months.Add(10, "NOVEMBER");
Months.Add(11, "DECEMBER");
I would like for the user to enter a month e.g."May" the be able to retrieve index[4] from an array within my program.
string Month = Console.ReadLine();
Basically to retrieve the index from the number of the corresponding Month entered.
Try this
var key = Months.Keys.Cast<int>().FirstOrDefault(v => Months[v] == "MAY");
Note: Don't forget to include this namespace - using System.Linq;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With