using System; //C#标配,写就对了
namespace RectangleApplication
{
class Rectangle
{
// 成员变量
double length;
double width;
public void Acceptdetails() //先执行该函数获值
{
length = 4.5;
width = 3.5;
}
public double GetArea()
{
return length * width; //计算面积
}
public void Display()
{
Console.WriteLine("Length: {0}", length); //控制台输出
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
static void Main(string[] args) //Main函数
{
Rectangle r = new Rectangle(); //实例化
r.Acceptdetails();
r.Display();
Console.ReadLine(); //防止闪退
}
}
}
1. C#基本语法
最新推荐文章于 2021-09-23 18:01:17 发布