发布时间:2019-07-31 11:20:26
定义一个点的类(Point),包含2个成员变量(x,y),并包含一个点的信息打印函数(Display)。
没有比这个更简单的C#类了,看下教程啊
class Point {
int x,y;
void Display()
{
Console.WriteLine("x="+x+",y"+y);
}
}
// Point类public class Point{ private int x; private int y; public Point(int x, int y) { this.x = x; this.y = y; } public int X { get{ return x;} set{ x = value;} } public int Y { get{ return y;} set{ y = value;} } } // Circle类, 继承Point类作为圆心public class Circle : Point{ float r; //半径 public Circle(int x, int y, float r):base(x, y) { this.r = r; } // 获取或设置圆心 public Point Center { get { return this;} set { this.X = value.X; this.Y = value.Y; } } // 获取或设置半径 public float Radius { get{ return r;} set { r = value;} } // 其他属性、方法……}
5 1