C#VS错误:类不包含构造函数(即使在类本身中添加一个)

Art*_*ani 0 c# constructor

在VS C#Express上,运行以下代码时出现此错误:

'myComponent.SettingsComponentAttributes'不包含带有1个参数的构造函数.

我已尝试在类本身中添加构造函数,但同样的消息应用于新构造函数:

public override void CreateAttributes()
{
    m_attributes = new SettingsComponentAttributes(this);
}

public SettingsComponentAttributes(SettingsComponentAttributes obj)
{
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 7

您的类没有声明任何构造函数,因此它等同于具有单个无参数构造函数:

public SettingsComponentAttributes()
{
}
Run Code Online (Sandbox Code Playgroud)

你试图将一个argument(this)传递给构造函数 - 这是行不通的.您需要更改构造函数调用,或声明适当的构造函数.

您还应该仔细查看错误消息,找出为什么需要在Stack Overflow上询问.哪一条消息对你不清楚?修改C#知识的那个方面.理解错误消息是成为优秀开发人员的一个非常重要的部分,这一点非常明确:

  • 您正在尝试使用带有1个参数的构造函数
  • 没有这样的构造函数