class Vector2Dpostion
{
private int x;
private int y;
public Vector2Dpostion(int x, int y) //对象初始化后,执行构造函数设置字段的初始值
{
Console.WriteLine("Vector2Dpostion 构造函数被调用");
this.x = x;
this.y = y;
}
public int Xattribute //属性X,通过属性的get和set方法可以对属性进行赋值和设置,可以实现对数据的保护
{
set
{
if (value > 1000)
Console.WriteLine("必须设置小于1000的值");
else
x = value;
}
get
{
return x;
}
}
public int Yattribute
{
set
{
if (value > 1000)
Console.WriteLine("必须设置小于1000的值");
else
y = value;
}
get
{
return y;
}
}
public int XYattribute //Get属性 XYattribute
{
get
{
Console.WriteLine("XYattribute属性get被调用");
return x * y;
}
}
bool Funtionsetx(int x)
{
this.x = x;
if (this.x > 100)
return false;
else
return true;
}
}
类的构造函数,属性 和方法
最新推荐文章于 2022-10-30 16:59:19 发布