【发布时间】:2018-05-29 20:49:38
【问题描述】:
所以我有这个哈希表
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");
我希望用户输入一个月,例如“May”能够从我的程序中的数组中检索索引 [4]。
string Month = Console.ReadLine();
基本上是从输入的对应月份数中检索索引。
【问题讨论】:
-
为什么不使用
Dictionary<int,string>()还有TryGetValue()方法
标签: c# collections hashtable