【问题标题】:Error: Class does not contain a constructor that takes 3 arguments错误:类不包含采用 3 个参数的构造函数
【发布时间】:2013-10-29 16:12:53
【问题描述】:

我的班级的构造函数有问题。 我有一个名为 DASHBOARD 的类,它继承自它的基类 LINKS。

public class Link
{
    private Page aPage;

    public Page myPage
    {
        get { return aPage; }
        set { aPage = value; }
    }
    public Link(int buildingID, Page mypage)
    {
        myPage = mypage;
    }
}


public class Dashboard : Link
{
    private int abuildingid;
    private int acustomerid;

    public int BuildingID
    {
        get { return abuildingid; }
        set { abuildingid = value; }
    }
    public int CustomerID
    {
        get { return acustomerid; }
        set { acustomerid = value; }
    }


    public Dashboard(int buildingid, int customerid, Page mypage)
        : base(buildingid, mypage)
    {
        BuildingID = buildingid;
        CustomerID = customerid;
    }

当我写代码时

新仪表板(buildingID、customerID、this)

我收到一个错误:错误 14:“仪表板”不包含采用 3 个参数的构造函数

我做错了什么?

【问题讨论】:

  • 什么是“这个”?我的猜测是“this”不是 Page 的一个实例。
  • 你的代码编译得很好。你确定你没有多个名为 Dashboard 的类并且它正在解决错误的类吗?或者,也许您的代码在与您定义 Dashboard 类的位置不同的项目中给出了错误,并且它没有引用最新版本的程序集?这可能是由于构建错误或硬引用 DLL 而不是项目引用而发生的。
  • @StealthRabbi 我很确定如果是这种情况,错误将是cannot convert from TypeA to 'Page'
  • 与你的问题无关,但我注意到你在 Link 的构造函数中没有对 buildingID 做任何事情。
  • @peer 根本不是重复的。

标签: c# class oop


【解决方案1】:

我想通了!

我有一个名为 Dashboard.aspx 的页面。所以这两个类名在我没有意识到的情况下混淆了。

这就是为什么有时有效,有时无效。

感谢大家的 cmets。为 Trevor Elliot 欢呼 3 次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 2013-02-16
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多