马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
C# 是一种面向对象的编程语言。在面向对象的步伐计划方法中,步伐由各种相互交互的对象构成。雷同种类的对象通常具有雷同的范例,大概说,是在雷同的 class 中。
比方,以 Rectangle(矩形)对象为例。它具有 length 和 width 属性。根据计划,它大概须要担当这些属性值、盘算面积和体现细节。
让我们来看看一个 Rectangle(矩形)类的实现,并借此讨论 C# 的根本语法:
起首新建一个控制台,如下图:
- using System;
- namespace RectangleApplication
- {
- class Rectangle
- {
- // 成员变量
- int length;
- int width;
- public void Acceptdetails()
- {
- length = 1;
- width = 2;
- }
- public int 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)
-
复制代码 |