C#矩形的周长和面积
来源:百度知道 编辑:UC知道 时间:2024/06/01 14:45:23
Rectangle类:
class Rectangle
{
private double width;
private double height;
public double Width
{
get { return width; }
set { width = value; }
}
public double Height
{
get { return height; }
set { height = value; }
}
public double Area
{
get
{
return Width * Height;
}
}
public double Circumference
{
get
{
return (Width + Height) * 2;
}
}
public Rectangle(double width, double height)
{
Width = width;
Height = height;
}
}
键盘处理范例:
static void Main(string[] args)
{
Console.WriteLine("Please enter the Width and Height like \" 100, 100\", enter \"quit\" for quit");
bool isOut = false;
while(!isOut)
{
string rectInfo = Console.ReadLine();
if (!rectInfo.Equals("quit"))
{
try
{
string[] rectWidt