直接按题目的要求写就可以了,如下:
using System;
namespace ConsoleApplication1
{
public class Rectangle
{
private double m_width, m_height;
// 构造函数
// width:宽
// heigh:长(高)
public Rectangle(double width, double height)
{
m_width = width;
m_height = height;
}
// Area方法:计算面积
public double Area()
{
return m_width * m_height;
}
}
class Program
{
static void Main(string[] args)
{
Rectangle rect = new Rectangle(2.5, 1.5);
Console.WriteLine("Area = {0}", rect.Area());
Console.ReadKey();
}
}
}
// 输出
// Area = 3.75