hashtable 集合中怎样访问或者遍历其中的元素? 请多指教
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Third
{
class Program
{
static void Main(string[] args)
{
Hashtable has = new Hashtable();
Car car1 = new Car("大黄蜂");
Car car2 = new Car("007");
Car car3 = new Car("兰博基尼");
//Add方法
has.Add(1,car1);
has.Add(2,car2);
has.Add(3,car3);
Console.WriteLine("集合中共有{0}个元素",has.Count);
以下是我写的:运行不出来正确结果
for (int i = 0; i < has.Values.Count; i++)
{
Car car = has.Values as Car;
Console.WriteLine(car);
}
}
}
}