跳到主要内容

csharp / c#

官方文档: https://learn.microsoft.com/zh-cn/dotnet/csharp/

使用VS code https://learn.microsoft.com/zh-cn/training/modules/install-configure-visual-studio-code/6-exercise-configure-visual-studio-code

C#(读作“See Sharp”)是一种新式编程语言,不仅面向对象,还类型安全。

Hello world

using System;

class Hello
{
static void Main()
{
Console.WriteLine("Hello, World");
}
}

类型

  • 值类型
    • 简单类型
      • 有符号整型 sbyte short int long
      • 无符号整型 byte ushort uint ulong
      • Unicode字符 char 表示 UTF-16 代码单元
      • IEEE 二进制浮点 float double
      • 高精度十进制浮点数 decimal
      • 布尔值 bool (true或者false)
    • 枚举类型
    • enum E {…}
    • 结构类型 struct S {….}
    • null
    • 元组值类型
      • 格式为 (E1,E2,…)
  • 引用类型
    • 类 类型
      • 所有类的最终基类 object
      • Unicode 字符串 string
      • 用户定义类型
        • class A {….}
      • 接口类型
        • interface I
      • 数组类型
        • int[] int[][]
      • 委托类型
        • 用户定义类型 delegate int D(…)

程序结构

c# 中结构概念包括 程序,命名空间,类型,成员,程序集

  • 程序声明类型

  • 类型包含成员,并被整理到命名空间中。

  • 类型示例包括类,结构和接口。

  • 成员示例包括字段,方法,属性和事件。

  • 编译完的c#程序实际上会打包到程序集

  • 程序集的文件扩展名通常为 .exe或 .dll (库文件)

  • 包管理工具