【发布时间】:2013-03-07 03:42:34
【问题描述】:
我很困惑为什么这不会运行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Buyer : User
{
public void AuctionWon()
{
}
}
}
我得到“不包含带 0 个参数的构造函数”。我事先已经搜索过帮助,但没有找到有用的结果。
这是用户类
public class User
{
private int accountNo;
private int password;
public User(int accountNo, int password)
{
this.accountNo = accountNo;
this.password = password;
}
public bool Validatepassword(int userpassword)
{
if (password == userpassword)
{
return true;
}
else
{
return false;
}
}
public int GetAccountNo()
{
return accountNo;
}
}
【问题讨论】:
-
请显示类用户...
-
由于您没有在任何地方调用无参数构造函数,显然您没有向我们展示产生错误的代码。
-
在User类中添加构造函数
-
C# does not contain a constructor?或User?如果您从 User 继承并且 User 没有 0 参数构造函数,您将收到该错误。