麻烦有解析下面这个程序 要详细的哦 class Program {
static Hashtable table = new Hashtable();
static void Main(string[] args)
{
table.Add(1, "一月份January");
table.Add(2, "二月份February");
table.Add(3, "三月份March");
table.Add(4, "四月份April");
table.Add(5, "五月份May");
table.Add(6, "六月份June");
table.Add(7, "七月份July");
table.Add(8, "八月份August");
table.Add(9, "九月份September");
table.Add(10, "十月份October");
table.Add(11, "十一月份November");
table.Add(12, "十二月份December"); int month = 0;
while (true)
{
Console.WriteLine("请输入月份的数字(输入0退出):");
if (!int.TryParse(Console.ReadLine(), out month))
{
Console.WriteLine("输入错误,请重新输入。");
continue;
}
if (month == 0)
{
break;
}
else if (month > 0 && month <= 12)
{
Console.WriteLine(table[month]);
}
else
{
Console.WriteLine("输入错误");
}
} }
}
}
static Hashtable table = new Hashtable();
static void Main(string[] args)
{
table.Add(1, "一月份January");
table.Add(2, "二月份February");
table.Add(3, "三月份March");
table.Add(4, "四月份April");
table.Add(5, "五月份May");
table.Add(6, "六月份June");
table.Add(7, "七月份July");
table.Add(8, "八月份August");
table.Add(9, "九月份September");
table.Add(10, "十月份October");
table.Add(11, "十一月份November");
table.Add(12, "十二月份December"); int month = 0;
while (true)
{
Console.WriteLine("请输入月份的数字(输入0退出):");
if (!int.TryParse(Console.ReadLine(), out month))
{
Console.WriteLine("输入错误,请重新输入。");
continue;
}
if (month == 0)
{
break;
}
else if (month > 0 && month <= 12)
{
Console.WriteLine(table[month]);
}
else
{
Console.WriteLine("输入错误");
}
} }
}
}
在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中key通常可用来快速查找,同时key是区分大小写;value用于存储对应于key的值。
。。//同上
、、、、//同上
table.Add(12, "十二月份December");//同上 while (true)表示一个无限循环Console.WriteLine("请输入月份的数字(输入0退出):");//表示在控制台输出一行信息 内容为"请输入月份的数字(输入0退出):" if (!int.TryParse(Console.ReadLine(), out month))//ReadLine是让用户输入的指令,这行的意思就是用户如果输入的不是int类型的值,就执行块中的报错信息
if (month == 0)//如果用户输入的值为0,则终止此循环
{
break;//break表示终止while循环
}else if (month > 0 && month <= 12)//否则如果用户输入的是大于0小于等于12的
{
Console.WriteLine(table[month]);//输出table键的对应值 这里的键指的是month,也就是用户输入的值,举个例子 比如键为2 则输出结果-> 二月份February
}
else
{
Console.WriteLine("输入错误");//不解释
}