首页 > 解决方案 > “帐户”不包含“提款”的定义,并且没有可访问的扩展方法“提款”错误

问题描述

完整错误:

“Account”不包含“Withdraw”的定义,并且找不到接受“Account”类型的第一个参数的可访问扩展方法“Withdraw”

using System;

namespace Account
{
    class TestAccount
    {
        public string Name;
        public decimal Balance;

        public void Account(string Name, decimal Balance)
        {
            this.Name = Name;
            this.Balance = 100;

        }

        //Accessor
        public string getName()
        {
            return this.Name;
        }
        public string getBalance()
        {
            return this.Balance.ToString("C");;
        }
        //Mutators
        public void setName(string Name)
        {
            this.Name = Name;
        }
        public void setBalance(decimal Balance)
        {
            this.Balance = Balance;
        }
        //Methods

        public void Deposit(decimal amount)
        {
            Console.WriteLine("How much would you like to deposit? Enter an amount: ");
            decimal AmountAdded = Convert.ToDecimal(Console.ReadLine());
            Balance = amount + AmountAdded;
            amount = Balance;

            Console.WriteLine("You just added: " + amount.ToString("C"));
        }

        public void Withdraw(decimal amount)
        {
            Console.WriteLine("How much would you like to Withdraw? Enter an amount: ");
            decimal AmountWithdraw = Convert.ToDecimal(Console.ReadLine());
            Balance = amount - AmountWithdraw;
            amount = Balance;

            Console.WriteLine("You just Withdrew: " + amount.ToString("C"));
        }

        public void Print()
        {
            Console.WriteLine("The name of the account is " + Name + "Your Balance is: " + Balance.ToString("C"));
        }
    }
}

这是我的主要课程

在此处输入图像描述

标签: c#classvisual-studio-code

解决方案


推荐阅读