写代码就行:
急啊..
会几题写几题,在解答的时候请在前面写第几题的...
1..编写程序,实现城市区号查询,如果系统中没有这个区号,请用户输入,使用Dictionary集合
2.编写一个程序,实现文件的复制,尽量使用文件选择对话框和文件保存对话框控件
写代码就行:
急啊..
会几题写几题,在解答的时候请在前面写第几题的...
1..编写程序,实现城市区号查询,如果系统中没有这个区号,请用户输入,使用Dictionary集合
2.编写一个程序,实现文件的复制,尽量使用文件选择对话框和文件保存对话框控件
/// <summary>
/// 城市区号映射类
/// </summary>
public class CityNumMapping
{
//保存城市及对应的区号
private Dictionary<string, string> cityNum;
public CityNumMapping()
{
this.cityNum = new Dictionary<string, string>();
this.initCity();
}
//根据城市名称获取区号
public string GetCityNumByCityName(string cityName)
{
if(!this.cityNum.Keys.Contains(cityName))
{
return string.Empty;
}
return this.cityNum[cityName];
}
//初始化城市及对应区号
private void initCity()
{
this.cityNum.Add("北京","010");
this.cityNum.Add("广州", "020");
//省略...
this.cityNum.Add("上海", "021");
}
}
/// <summary>
/// 应用程序
/// </summary>
class Program
{
static void Main(string[] args)
{
CityNumMapping cityNumMapping = new CityNumMapping();
string cityName=string.Empty;
string cityNum = string.Empty;
Console.Write("请输入城市名称:");
cityName = Console.ReadLine();
while(1==1)
{
cityNum = cityNumMapping.GetCityNumByCityName(cityName);
if (cityNum == string.Empty)
{
Console.Write("无此城市,请重新输入城市名称:");
cityName = Console.ReadLine();
}
else
{
Console.WriteLine("该城市对应的区号是:"+cityNum);
break;
}
}
Console.ReadLine();
//if (cityNum == "无对应区号")
//{
// Console.Write("无对应城市,请重新输入城市名称:");
//}
}
}