The property or indexer must have at least one accessor

I am learning C # trying to access accessories at the moment.
I'm going crazy looking at this, I have no idea what I did wrong:

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

    // **ACCESSORS** 
    public int SavingsAccount
    {
        set
        {
            _initialDeposit = value;
        }
        get
        {
            return _initialDeposit;
        }
    }
}

      

The form looks like this:

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;
    }
}

      

But I am getting this error:

The property or indexer must have at least one accessor

+3


source to share


1 answer


I have no errors. Move private account location BankAccount _myAccount;



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BankForm
{

    public partial class BankForm : Form
    {
        public BankForm()
        {
            InitializeComponent();
            _myAccount = new BankAccount();
        }
        private BankAccount _myAccount;

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

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

        // **ACCESSORS** 
        public int SavingsAccount
        {
            set
            {
                _initialDeposit = value;
            }
            get
            {
                return _initialDeposit;
            }
        }
    }

}

      

+1


source







All Articles