using System;
namespace RectangleApplication
{
class Rectangle
{
double length;
double width;
public void accecptnum(){
length=4.0;
width=3.0;
}
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)
{
Rectangle r = new Rectangle();
r.accecptnum();
r.display();
Console.ReadLine();
}
}
}
运行结果:
本文介绍了一个简单的C#程序,用于定义矩形类并计算其面积。通过设置长度和宽度属性,程序能够准确地计算出矩形的面积并显示结果。
5567

被折叠的 条评论
为什么被折叠?



