// プロパティ
class Practice8_1
{
static void Main(string[] args)
{
// プロパティを介してprivateな変数にアクセスできる。
Sample s = new Sample();
s.Param1 = 10;
int n = s.Param1;
}
}
class Sample
{
private int _param1;
// SetterとGetterを定義する。
public int Param1
{
set
{
this._param1 = value;
}
get
{
return this._param1;
}
}
// 自動プロパティ
public int Param2 { get; set; }
// 読み取り専用
public int Param3 { get; private set; }
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme