编写一个控制台程序,创建哈希集合,内含部分国家的名称和首都,提示用户输入一个国家名称,则在哈希集合中查找该国首都名称并输出。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Hashtable hst = new Hashtable();
hst.Add("China", "Beijing");
hst.Add("Japan", "Tokyo");
hst.Add("Italy","Rome");
hst.Add("America", "Washington");
hst.Add("Canada", "Ottawa");
Console.WriteLine("Please input the name of country:");
while (true)
{
string str = Console.ReadLine();
if (hst.Contains(str))
{
Console.WriteLine("The capital is :{0}",hst[str]);
}
}
Console.ReadKey();
}
}
}