//时间
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Rectangle
{
class Program
{
static void Main(string[] args)
{
CRectangle rect1 = new CRectangle();
try
{
rect1.Width = Convert.ToInt32(Console.ReadLine());
rect1.Height = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
return;
}
catch (Exception a)
{
Console.WriteLine(a.Message);
Console.ReadKey();
return;
}
Console.WriteLine("面积{0}", rect1.Area());
Console.WriteLine("周长{0}", rect1.Perimeter());
Console.ReadKey();
}
}
class CRectangle
{
private int height;
private int width;
public int Width
{
set
{
if (value > 0)
width = value;
else throw new Exception("宽度应该大于零");
}
get
{
return width;
}
}
public int Height
{
set
{
if (value > 0) height = value;
else throw new Exception("高度应该大于零");
}
get
{
return height;
}
}
public int Area()
{
return width * height;
}
public int Perimeter()
{
return 2 * (width + height);
}
}
}
总结:不怎么会复数啊