我很困惑为什么这不会运行.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Buyer : User
{
public void AuctionWon()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到"不包含带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;
}
}
Run Code Online (Sandbox Code Playgroud)
PaR*_*RaJ 12
它看起来像你的基类(User类),没有任何具有0参数的构造函数.
您的用户类有一个类似于的构造函数:
public class User
{
public User(int accountNo, int password)
{
this.accountNo = accountNo;
this.password = password;
}
}
Run Code Online (Sandbox Code Playgroud)
和买方必须像以下一样继承:
public class Buyer : User
{
public Buyer(int accountNo, int password) : base(accountNo, password)
{
}
public void AuctionWon()
{
}
}
Run Code Online (Sandbox Code Playgroud)