“Object” does not contain a definition for “name”

后端 未结 6 1969
误落风尘
误落风尘 2021-01-28 21:39

I\'m having an error message that tells me this:

\'BankAccount.account\' does not contain a definition for \'withdraw\'.

Here\'s my code:

using S         


        
6条回答
  •  鱼传尺愫
    2021-01-28 22:10

    It looks like you simply missed the method from the base type:

    public virtual void Deposit(float amt)
    {
        balance += amt;
    }
    public virtual void Withdraw(float amt)
    {
        balance -= amt;
    }
    

    Note I changed "deposit" to +=, and made the method virtual so that subclasses can override the method, which is (I strongly suspect) what the intent is here. Additionally, float is a really bad choice for storing money. decimal might be a better choice. As a stylistic change, I also capitalized the names.

提交回复
热议问题