您好我最近開始學習C#並且有一些關於屬性的問題。 比方說,我有這樣的說法:在C中使用屬性獲取和注入字段#
private int minAge { get; set; }
這是否翻譯成這樣:
private int minAge
public int MinAge
{
get { return this.minAge; }
set { this.minAge = Convert.ToInt16(TextBox1.Text); } //this is what I would like to set the field to
}
比方說,我有一個按鈕,當我按下那個按鈕,我需要它來設置MINAGE場之後返回數據。我可以如何實現這一目標?
我試過,但它似乎不工作:
minAge.get //to return data
minAge.set = Convert.ToInt16(TextBox1.Text); //to set the data
我試着按照你說的方式去做:public int minAge {get;組; },minAge = 10; int a = minAge.get;但我得到一個erorr SAIS INT不包含定義獲取 – user1525474
@ user1525474:編輯代碼 –
okk因此換句話說C#自動調用get和set方法?我只需要一個確認,以瞭解如果我udnerstand這個權利 – user1525474