亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> C语言

C# 基础语法与面向对象核心:类、成员、实例化、标识符与关键字

C# 是面向对象语言:程序由对象组成,对象通过方法交互。同类对象共享类型定义。

矩形类实战示例

using System;
namespace RectangleApplication {
  class Rectangle {
    double length, 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();
    }
  }
}

输出:Length: 4.5 Width: 3.5 Area: 15.75

核心语法要素

标识符命名规则

C# 关键字完整表

保留关键字 (78个)
abstractasbaseboolbreakbytecase
catchcharcheckedclassconstcontinuedecimal
defaultdelegatedodoubleelseenumevent
explicitexternfalsefinallyfixedfloatfor
foreachgotoifimplicitinin(generic)int
interfaceinternalislocklongnamespacenew
nullobjectoperatoroutout(generic)overrideparams
privateprotectedpublicreadonlyrefreturnsbyte
sealedshortsizeofstackallocstaticstringstruct
switchthisthrowtruetrytypeofuint
ulonguncheckedunsafeushortusingvirtualvoid
volatilewhile
上下文关键字 (13个)
addaliasascendingdescendingdynamicfromget
globalgroupintojoinletorderbypartial(type)
partial(method)removeselectset

C语言

  1. C++ 类模板实战指南:编写灵活的类型无关代码
  2. C 语言存储类完全解析:auto、extern、static、register
  3. C 语言基础语法精通:Token、分号、注释与标识符规范
  4. C++核心语法与面向对象基石深度解析
  5. C++多态实战指南:虚函数、动态绑定与纯虚函数
  6. C++数据抽象实战:接口与实现分离的设计艺术
  7. C++数据封装:守护代码安全的核心机制
  8. C# 程序结构解析:从 Hello World 看命名空间、类、Main 入口与编译运行
  9. C# 封装详解:访问修饰符与面向对象设计最佳实践
  10. C# 类完全指南:定义、封装、构造函数、析构函数与静态成员
  11. MATLAB 基础语法速成:交互计算、变量、运算符、格式控制与注释
  12. Java 基础:掌握基本语法