日期:2014-05-17  浏览次数:20797 次

看别人的一段代码,有个地方看不明白,求指教

public class Garage:IEnumerable  
    {  
        Car[] carArray = new Car[4];  
        //启动时填充一些Car对象  
       public Garage()  
        {  
           carArray[0] = new Car("Rusty", 30);  
           carArray[1] = new Car("Clunker", 50);  
           carArray[2] = new Car("Zippy", 30);  
           carArray[3] = new Car("Fred", 45);  
       }  

        public IEnumerator GetEnumerator()  
       {  
           return this.carArray.GetEnumerator();  
        }  
    }  


问题:提示我的Car[](未能找到命名空间或类型,是否缺少using引用集)
可是我看他的代码也没有给Car[]新定义一个类啊?那就算是给Car[]新定义一个类,那怎么新定义的这个Car[]类应该怎么写呢?

------解决方案--------------------
public class Car
{
    public Car(){};
}

------解决方案--------------------
肯定少了一个Car 类,类似

public class Car
            {
                public string Type { get; set; }
                public int Count { get; set; }
            }

------解决方案--------------------
 public class Car
    {
        public Car(string type, int count)
        {
            Type = type;
            Count = count;
        }
        public string Type { get; set; }
        public int Count { get; set; }
    }