.NET

微软开发的应用程序框架,包含一系列库、运行时等内容。
微软中间语言(MSIL, Microsoft Intermediate Language)
公共语言运行时(CLR, Common Language Runtime)
JIT编译(just-in-time compilation)

C#

命令行运行

dotnet run --project Hello

Main方法

class Program
{
    static void Main(string[] args)
    {
    }
}

类型

继承自 System.Object
值类型、引用类型、指针

基本类型

sbyte, byte, short, ushort, int, uint, long, ulong, float, double, decimal, bool, char

结构体(值类型)

public struct Point
{
    public int x;
    public int y;
    public Point(int x_, int y_)
    {
        x = x_;
        y = y_;
    }
}
// Point p = new Point(1, 2);

枚举

public enum Color
{
    Red = 0, Blue = 1, Yellow = 2, Purple = 8, Black
}

元组

(double, int) t1 = (4.5, 5);
Console.WriteLine($"{t1.Item1}, {t1.Item2}");

引用类型

string s1 = new string("hello world");
string s2 = "hello world";

装箱和拆箱

object类

  • ToString
  • GetHashCode
  • GetType

String

string s1 = "abc";
string s2 = @"a
b
c";
string s3 = $"{1} + {1} = {1 + 1}";

自动推导

var x = 4;
var y = "abc";