描述平面坐标的类,其中包含两个私有成员,分别是点的x坐标和y的坐标,为私有成员编写属性过程,添加有参数和无参数的构造函数,在Main()主函数中生成类对象,并输出类的坐标值。
public class Point
{
private float x;
private float y;
public float X
{
get{return x;}
set{x=value;}
}
public float Y
{
get{return y;}
set{y=value;}
}
public Point()
{
x=0;
y=0;
}
public Point(float x,float y)
{
this.x=x;
this.y=y;
}
}
void main()
{
Point p=new Point(1,2);
console.WriteLine(p.X.ToString());
console.WriteLine(p.Y.ToString());
}
public class Point
{
private float x;
private float y;
public float X
{
get{return x;}
set{x=value;}
}
public float Y
{
get{return y;}
set{y=value;}
}
public Point()
{
x=0;
y=0;
}
public Point(float x,float y)
{
this.x=x;
this.y=y;
}
}
void main()
{
Point p=new Point(1,2);
console.WriteLine(p.X.ToString());
console.WriteLine(p.Y.ToString());
}