由于其在窗口窗体中的保护级别而无法访问

本文关键字:访问 保护 于其 窗口 窗体 | 更新日期: 2023-09-27 18:34:10

这是我遇到的第一个问题。真的,我不知道这是为什么。我读了一点,并将我看到的大部分重要内容(如果不是全部)公开。所以我想也许这里有人可以解释这一点。另外,我正在尝试使它当有人在提款文本框中输入并单击它时,aMtBox 将显示这样的金额。这可行吗?还是我在这里做错了什么

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
    BankAccount a = new BankAccount();
    public Form1()
    {
        InitializeComponent();
        decimal iBa = 300.00m;
        this.aMtBox.Text = iBa.ToString();
    }
    public void withdrawl_Click(object sender, EventArgs e)
    {
        MessageBox.Show("The balace is... {0:c2}", a.balance.ToString());
    }
    public class BankAccount
    {
        decimal balance;
        decimal iBa;
        decimal num1;
        public decimal Balance
        {
            get { return balance;}
        }
        public decimal IBa
        {
            get { return iBa;}
        }
        public decimal Num1
        {
            get { return num1;}
        }
        public BankAccount()
        {
            iBa = 300.00m;
            num1 = 0.00m;
            balance = iBa - num1;
        }
    }
}
}

由于其在窗口窗体中的保护级别而无法访问

更改

a.balance.ToString()

a.Balance.ToString()

a.由于是私有的,外部类无法访问平衡。