2

这是我遇到的第一个问题。真的,我不知道这是为什么。我读了一点,并将我看到的大部分重要内容公之于众(如果不是全部的话)。所以我想也许这里有人可以解释一下。另外,我正在尝试将其设置为当有人在提款文本框中键入并单击它时,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;
        }
    }
}
}
4

1 回答 1

3

改变

a.balance.ToString()

a.Balance.ToString()

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

于 2013-10-05T00:52:48.963 回答