Animal[] animalArray=new Animal[2];
Cow myCow1=new Cow("Deirdre");
animalArray[0]=myCow1;
visual c# 2010,不知道为什么错了,提示原因如标题

解决方案 »

  1.   

    怪我没表达清楚,animal是COW类基类,感觉不应该是这个原因
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections ;namespace Ch11Ex01
    {
        class Program
        {
            static void Main(string[] args)
            {
                 Console.WriteLine("create an array type collection of animal");}
                Animal[] animalArray = new Animal[2];
                Cow myCow1=new Cow("Deirdre");
                animalArray[0] = myCow1;
              
              
            }
        }
    animal类:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace Ch11Ex01
    {
        public abstract class  Animal
        {
            protected string name;
            public string Name
            { get { return name; } set { name = value; } }
            public Animal() { name = "the animal with no name"; }
            public Animal(string newName) { name = newName; }
            public void Feed() { Console.WriteLine("{0} has been fed",name);}
        }
    }Cow类:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace Ch11Ex01
    {
        public class Cow:Animal 
        {
            public void Milk() { Console.WriteLine("{0} has been milked",name);}
            public Cow(string newName): base(newName) { }
        }
    }
      

  3.   

    我发现把第一句Console.writeline去掉之后,就好了,求解释
      

  4.   

    没发现你Console.WriteLine("create an array type collection of animal");}后面多了个花括弧吗……
      

  5.   

    我发现了
    编程习惯要养好
    推荐一篇
    http://topic.csdn.net/u/20120109/16/e523711d-9451-41e0-932f-5bcaa8a438a5.html