public int MyIntProp{
get{
}
set{
}
}
定义需要名字和类型。
属性包括get和set两个块,并不一定要同时存在
取得属性的值,会访问属性中的get块,这个值类型必须和属性的类型一样。
给属性设置值,用set块,可以在set块中通过value访问已设置的值。
public Vector3(int x, int y, int z)
{
Console.WriteLine("构造函数2被调用了");
this.x = x;
this.y = y;
this.z = z;
}
public int MyIntProperty
{
get//没有get块 不可以通过属性取值
{
Console.WriteLine("get块被调用"