我是C#的新手,正在處理類和理解它們。我的問題是我不瞭解如何創建Get
以檢索專用變量_yourname
和Set
以設置專用變量_yourname
。構造函數GetInfo
namespace WindowsFormsApplication1
{
class InputClass
{
private string _yourName;
public string _banner;
public virtual void GetInfo();
public InputClass(String _banner)
{
_banner = "Enter your name";
}
}
}
也許我使用了錯誤的功能GetInfo
。但我也想知道,當我有GetInfo
如果在()
我應該寫_yourname
在它。
你看了這頁嗎? http://msdn.microsoft.com/en-us/library/wxh6fsc7.aspx – 2012-02-06 21:07:25
在構造函數中使用'this._banner',否則你只是設置本地變量。 – SomeWritesReserved 2012-02-06 21:15:07