今天开始学习C#啦
using System; //引用
namespace RectangleApplication //命名空间
{
class Rectangle //类声明
{
double length; //成员变量
double width; //成员变量
public void AcceptDetails() //成员方法,无返回
{
length=3.5;
width=4.5;
}
public double GetArea() //成员方法,返回double类型
{
return length * width;
}
public void Display() //成员方法,无返回
{
Console.WriteLine("length:{0},width:{1},area:{2}",length,width,GetArea());
//{x}为占位符,与后面那段参数一一对应
Console.ReadKey();
//等待键盘输入任意字符,避免一闪而过
}
}
class ExecuteRectangle //包含 Main() 方法和实例化 Rectangle 类的类。
{
static void Main(string[] args)
{
Rectangle r = new Rectangle(); //声明实例
r.AcceptDetails(); //执行方法
r.Display(); //执行方法
}
}
}
//注意{}符号的成对