链接到子类 - 一个工作,另一个不工作

时间:2015-04-27 00:42:14

标签: c# subclass

对于今天到期的作业的最后一部分,我必须实例化一个基类和我之前生成的两个子类。虽然我很确定如何实例化它们,但我很早就遇到了错误:

using ClassLibrary1;
using ClassLibrary2;
using ClassLibrary3;
namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        private Tennis aTennis;
        private Football aFootball;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

网球和足球是两个子类,我已经验证了这些类中的布局是相同的。然而,只有“足球aFootball”被VS认为是一个子类,“网球aTennis”提出了一个:

  

“无法找到命名空间”

...错误。这个应用程序或者网球类本身是错误吗?

编辑:网球和足球代码,如下:

网球:

namespace ClassLibrary2
{
   public class Tennis :  Team
    {
       private string assistantname;
        public  Tennis(  )  :  base  (  )
        {
        }
        public Tennis(string sport, string cname, int pamount,
        int anAge, string asname)
        :base(sport,  cname,  pamount, anAge)
        {
            assistantname = asname;
        }
        public string Assistantname
        {
            get
            {
                return assistantname;
            }
        }
        public override int GetSeasonMonths()
        {
            return 3;
        }
        public int CallOverriddenGetSeasonMonths()
        {
            return base.GetSeasonMonths();
        }
        public override string ToString()
        {
            return "The training assistant's name is" + assistantname;
        }
    }
}

足球:

namespace ClassLibrary3
{
    public class Football : Team
    {
        private string mascot;
        public Football()
            : base()
        {
        }
        public Football(string sport, string cname, int pamount,
        int anAge, string mcot)
            : base(sport, cname, pamount, anAge)
        {
            mascot = mcot;
        }
        public string Mascot
        {
            get
            {
                return mascot;
            }
        }
        public override int GetSeasonMonths()
        {
            return 3;
        }
        public int CallOverriddenGetSeasonMonths()
        {
            return base.GetSeasonMonths();
        }
        public override string ToString()
        {
            return "The team mascot is the" + mascot;
        }
    }
}

0 个答案:

没有答案