Hashtable hashtable = new Hashtable();//实例化Hashtable对象
hashtable.Add("ID", "BH001");//向Hashtable中添加元素
hashtable.Add("Name", "张三");
hashtable.Add("Sex", "男");
Console.WriteLine("\t 键\t 值");
foreach (DictionaryEntry dicEntry in hashtable)
{
Console.WriteLine("\t"+dicEntry.Key+"\t"+dicEntry.Value);
}
Console.ReadKey();
以上是用foreach遍历的Hashtable,请问各位用for循环怎么做?上面的遍历还可以简化么? |