using System;
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) {
Rectangle r = new Rectangle();
r.Acceptdetails();
r.Display();
Console.ReadLine();
}
}
}
知识点总结:
1、using 关键字: 用于在程序中包含命名空间。一个程序可以包含多个using语句。
2、class 关键字: 用于声明一个类
3、单行注释 ‘//’; 多行注释“/* ... */"
4、类ExecuteRectangle 是一个包含Main()方法和实例化Rectangle类的类。
5、标识符:用来识别类、变量、函数或任何其他用户定义的项目。在C#中,类的命名需要遵循以下规则:
数据类型:
object obj; bbj = 100; // 装箱
String str = "Nola‘s app"; @"Nola‘s app"
type* identifier; char* cptr;
原文:https://www.cnblogs.com/Nola-blog/p/14464148.html