2013-10-05 29 views
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

你從哪裏得到錯誤,它的實際文字是什麼? – millimoose

+1

最新錯誤?什麼不行? – AlwaysAProgrammer

+2

對不起,它的MessageBox.Show(「The balace is ... {0:c2}」,a.balance.ToString());並說其「錯誤由於其保護級別,'WindowsFormsApplication2.Form1.BankAccount.balance'無法訪問」紅線處於欠平衡狀態。 – Zoro

回答

3

變化

a.balance.ToString() 

a.Balance.ToString() 

a.balance是無法訪問外部類,由於是私人。

+0

我向上帝發誓我在發佈之前就這樣做了。我再次嘗試它,它的工作原理。我想我現在要暫停編程。 – Zoro

+0

+1,@Azzamean,別忘了[標記爲答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235) – Habib

+0

@哈比卜我知道,我必須等待近10分鐘才能這樣做。在那之後我真的很想面對自己。 – Zoro

相關問題