属性或索引器必须至少有一个访问器

Dar*_*nan 5 c#

我正在学习 C#,目前正在尝试掌握访问器。
看着这个我快疯了,我不知道我做错了什么:

class BankAccount
{
    // *PROPERTIES* 
    private int _initialDeposit = 0;

    // **ACCESSORS** 
    public int SavingsAccount
    {
        set
        {
            _initialDeposit = value;
        }
        get
        {
            return _initialDeposit;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

表格如下所示:

public partial class BankForm : Form
{
    private BankAccount _myAccount;

    public BankForm()
    {
        InitializeComponent();
        _myAccount = new BankAccount();
    }

    private void initialDepositButton_Click(object sender, EventArgs e)
    {
        _myAccount.SavingsAccount = Convert.ToInt32(initialDepositTextBox.Text);
        bankAccountListBox.Text = "Account opened with initial Deposit " + initialDepositTextBox.Text;
    }
}
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

属性或索引器必须至少有一个访问器

jdw*_*eng 3

我没有收到任何错误。移动私人 BankAccount _myAccount 的位置;

\n\n
using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\n\nnamespace BankForm\n{\n\n    public partial class BankForm : Form\n    {\n        public BankForm()\n        {\n            InitializeComponent();\n            _myAccount = new BankAccount();\n        }\n        private BankAccount _myAccount;\n\n        private void initialDepositButton_Click(object sender, EventArgs e)\n        {\n            _myAccount.SavingsAccount = Convert.ToInt32(initialDepositTextBox.Text);\n            bankAccountListBox.Text = "Account opened with initial Deposit " + initialDepositTextBox.Text;\n        }\n\n    }\n    class BankAccount\n    {\n        // *PROPERTIES* \n        private int _initialDeposit = 0;\n\n        // **ACCESSORS** \n        public int SavingsAccount\n        {\n            set\n            {\n                _initialDeposit = value;\n            }\n            get\n            {\n                return _initialDeposit;\n            }\n        }\n    }\n\n}\n\xe2\x80\x8b\n
Run Code Online (Sandbox Code Playgroud)\n