关于c#:银行账户’不包含“银行账户”的定义


BankAccount' does not contain a definition for 'BankAccount

本问题已经有最佳答案,请猛点这里访问。

这是银行账户类别:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace BankAccount
{
    public abstract class BankAccount
    {
        protected static int numberOfAccounts = 100001;
        private double balance;
        private string owner;
        private string accountNumber;

        public BankAccount()
        {
            balance = 0;
            accountNumber = numberOfAccounts +"";
            numberOfAccounts++;
        }

        public BankAccount(string name, double amount)
        {
            owner = name;
            balance = amount;
            accountNumber = numberOfAccounts +"";
            numberOfAccounts++;
        }

        public BankAccount(BankAccount oldAccount, double amount)
        {
            owner = oldAccount.owner;
            balance = amount;
            accountNumber = oldAccount.accountNumber;
        }
}
}

这是支票账户类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace BankAccount
{
    class CheckingAccount : BankAccount
    {
        int fee = 15;
        public CheckingAccount(string name, double amount)
        {
           base.BankAccount(name, amount);
        }
        public new bool Withdraw(double amount)
        {
            double totalAmount = amount + fee;
            return base.Withdraw(totalAmount);
        }
    }
}

因为,base.BankAccount(name, amount);我出错了,

'BankAccount' does not contain a definition for 'BankAccount.'

银行账户是基础类,支票账户继承基础类。当我删除基本关键字时,它会说:

Non Invokable member cannot be used as a method.

总的来说,我创建了一个对象,我想接受一个main值——一个字符串和一个double,然后将它发送给CheckingAccount类,CheckingAccount构造函数应该运行,然后将值发送给BankAccount构造函数并进行计算。

我怎么修正这个错误

'BankAccount' does not contain a definition for 'BankAccount'

. ?谢谢,


C不象Java那样,在CelyBuffer之间调用Suffer(),需要添加":BASE(name,AMOUT)"来调用超级类构造函数。这样地:

1
2
3
4
public CheckingAccount(string name, double amount) : base(name,amount)
{

}


你可以这样称呼它。

1
2
3
4
public CheckingAccount(string name, double amount) : base (name, amount)
{

}