c# 设计一个矩形类,要求能够计算矩形的面积,比较两个矩形的大小
发布网友
发布时间:2024-10-05 05:18
我来回答
共1个回答
热心网友
时间:2024-10-10 07:36
public class Rectangle
{
private double length;
public double Length{
get
{
return length;
}
set
{
if(value > 0)
this.length = value;
}
}
private double width;
pubilc double Width{
get
{
return this.width;
}
set
{
if(value>0)
this.width = value;
}
}
private double area;
public double Area
{
get
{
return this.width*this.height;
}
}
}
public static void main(string[] args)
{
Rectangle r1= new Rectangle();
r1.Width =5;
r1.Height = 6;
Rectangle r2 = new Rectangle();
r2.Width = 3;
r2.Height=2;
if(r1.Area > r2.Area)
{
//r1面积大
}
//......
}