C#
![本页使用了标题或全文手工转换](https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Zh_conversion_icon_m.svg/35px-Zh_conversion_icon_m.svg.png)
![]() | |
编程范型 | 结构 |
---|---|
语言 | C |
发行时间 | 2000 |
| |
Windows、Linux、Mac OS X 、 Android | |
| |
.cs , .csx | |
docs | |
.NET、.NET | |
衍生 | |
C | |
C++、Java、Eiffel、Modula-3、Object Pascal | |
Clojure[4]、D |
C#
命名
[编辑]C#
设计目 标
[编辑]ECMA标准
- C#
旨 在 设计成 为一种「简单、现代、通用 」,以及面 向 对象的 程 序 设计语言 - 此种语言
的 实现,应提供 对于以下 软件工程 要素 的 支持 :强 类型檢 查、数 组维度 检查、未 初 始 化 的 变量引用 检测、自 动垃圾收集 (Garbage Collection,指 一种記憶體自動释放技术)。软件必须做到強大 、持久 ,并具有 较强的 编程生 产力。 - 此种语言为在
分布 式 环境中 的 开发提供 适用的 组件开发应用。 - 为使
程 序 员容易 迁移到 这种语言,源 代 码的可 移植 性 十 分 重要 ,尤 其是对于那 些已熟 悉C和 C++的 程 序 员而言 。 - 对国际化
的 支持 非常 重要 。 - C#适合为
独立 和 嵌入 式 的 系 统编写 程 序 ,从使用 复杂操作 系 统的大型 系 统到特定 应用的 小型 系 统均适用。
歷史
[编辑]版本
[编辑]語 言 特性
[编辑]指 针(Pointer)只 能 用 於不安全 模 式 之 中 。大 多數 對象 訪問 透過 安全 的 引用 实现,以避免 無效 的 調 用 ,並 且有許多 算法 用 於验证溢出 ,指 针只能 用 於調用 值类型 ,以及受垃圾收集 控 制 的 托 管 對象 。對象 不能 被 顯 式 釋放 ,代替 為當 不 存在 被 引用 時 透過 垃圾回收 器 回收 。只 允許 單一 繼承 (single inheritance),但 是 一個類可以實現多個接 口 (interfaces)。- C#
比 C++更 加 類型 安全 。默 认的安全 轉換 是 隱 含轉換 ,例 如由短 整 型 轉換 為 長 整 型 和 從 衍生類 轉換 為 基本 類 。而接口 布 尔型同 整 型 ,及枚舉型同 整 型 不 允許 隱 含轉換 ,非 空 指 针(透過 引用 相似 對象 )同 用 戶 定義 類型 的 隱 含轉換字 段 被 顯 式 的 確定 ,不同 於C++的 複製 構造 函數 。 数 组声明 語法 不同 ("int[] a = new int[5]"而不是 "int a[5]")。枚 舉位 於其所在 的 命名 空間 中 。- C#
中 沒 有 模 版 (Template),但 是 在 C# 2.0中 引入了 泛型(Generic programming),並 且支持 一 些C++模 版 不 支持 的 特性 。比 如泛型 參 數 中 的 類型 約束 。另一方面 ,表 達 式 不能 像 C++模 版 中 被 用 於類型 參 數 。 屬性 支持 ,使用 類似 訪問 成員 的 方式 調 用 。完 整 的 反射 支持 。
C# 2.0的 特性
[编辑]针对于.NET SDK 2.0(
部分 类
[编辑]file1.cs:
public partial class MyClass1
{
public void MyMethod1()
{
// implementation
}
}
file2.cs:
public partial class MyClass1
{
public void MyMethod2()
{
// implementation
}
}
泛型
[编辑]泛型,
它
泛型类中,
class Node<T, V>
where T : Stack, IComparable, new(), class
where V : Stack, struct
{...}
泛型
泛型类的
泛型类中
静 态類別
[编辑]迭代器
[编辑]yield return
类似于Pythonyield
// Method that takes an iterable input (possibly an array)
// and returns all even numbers.
public static IEnumerable<int> GetEven(IEnumerable<int> numbers)
{
foreach (int i in numbers)
{
if (i % 2 == 0) yield return i;
}
}
- foreach循环时考虑线
程 安全 性 ,不要 试图对被遍 历的集合 进行remove和 add等 操作 - IEnumerable
接 口 是 LINQ特性 的 核心 接 口 。只 有 实现了 IEnumerable接 口 的 集合 ,才能 执行相 关的LINQ操作 ,比 如select,where等
匿名 方法
[编辑]delegate void NumberChanger(int n);
NumberChanger nc = delegate(int x)
{
Console.WriteLine("Anonymous Method: {0}", x);
};
public void Foo(object parameter)
{
// ...
ThreadPool.QueueUserWorkItem(delegate
{
// anonymous delegates have full access to local variables of the enclosing method
if(parameter == ...)
{
// ...
}
// ...
});
}
委 托 的 协变和 逆 变
[编辑]属性 访问器 可 以被单独设置访问级别
[编辑]string status = string.Empty;
public string Status
{
get { return status; } // anyone can get value of this property,
protected set { status = value; } // but only derived classes can change it
}
可 空 类型
[编辑]int? i = null;
)null
给任
int? i = null;
object o = i;
if(o == null)
Console.WriteLine("Correct behaviour - runtime version from September 2005 or later");
else
Console.WriteLine("Incorrect behaviour - pre-release runtime (from before September 2005)");
??運算 子
[编辑](??
):如果
object nullObj = null;
object obj = new Object();
return nullObj ?? obj; // returns obj
int? i = null;
int j = i ?? 0; // Unless i is null, initialize j to i. Else (if i is null), initialize j to 0.
C# 3.0的 特性
[编辑]C# 3.0发布于2007
Linq
[编辑]语言from
, where
, select
"from
、where
select
类型初 始 化 器
[编辑]Customer c = new Customer();
c.Name = "James";
Customer c = new Customer() { Name = "James" };
集合 初 始 化 器
[编辑]MyList list = new MyList();
list.Add(1);
list.Add(2);
MyList list = new MyList { 1, 2 };
MyList
实现System.Collections.IEnumerable
且有Add
匿名 類型
[编辑]var x = new { Name = "James" };
局部 变量类型推断
[编辑]
var x = new Dictionary<string, List<float>>();
Dictionary<string, List<float>> x = new Dictionary<string, List<float>>();
它只
Lambda表 达式
[编辑]Lambda
listOfFoo.Where(
delegate(Foo x)
{
return x.Size > 10;
}
)
可 写 作
listOfFoo.Where(x => x.Size > 10);
编译
- 如果
只 有 一 个参数 ,可 以省略 括 号 (),例 如 item=>{Console.WriteLine("只 有 一 个参数 {0}的 Lambda表 达式",item); }; - 如果
只 有 一个返回值的语句,可 以省略 花 括 号 {}、return关键字 、分 号 ,例 如 item => {return item % 2 == 0;};改 写 成 :item =>item %2 == 0; - Lambda
表 达式可 以分配 给Func,Action或 Predicate委 托 。
自 动化属性
[编辑]编译
public string Name
{
get;
set;
}
扩展方法
[编辑]扩展
public static class IntExtensions
{
public static void PrintPlusOne(this int x)
{
Console.WriteLine(x + 1);
}
}
int foo = 0;
foo.PrintPlusOne();
- 扩展
方法 只 会 增加 编译器 的 工作 ,但 不 会 影 响程序 运行性能 (用 继承的 方式 为一个类型增加特性反而会影响性能) - 如果
原 来 的 类中有 一 个方法 ,跟扩展 方法 一 样,那 么扩展 方法 不 会 被 调用,编译器 也不会 提示
分部 方法
[编辑]分部 方法 (Partial methods)必须定 义在分部 类(partial classes)中 定 义分部 方法 需要 用 partial做修饰符分部 方法 不 一定总是有执行内容的,也就是 说定义的方法 可 以一句操作语句都没有分部 方法 返 回 值必须是void分部 方法 可 以是静 态(static)方法 分部 方法 可 以包含 参 数 ,参 数 可 以包含 以下 修 饰词:this,ref,params分部 方法 必须是 私有 (private)方法
partial class C
{
static partial void M(int i); // defining declaration
}
partial class C
{
static partial void M(int i)
{
dosomething();
}
}
C# 4.0的 特性
[编辑]dynamic类型
[编辑]C# 4.0
dynamic关键
dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
具 名 參 數 與 可 選 參 數
[编辑]public StreamReader OpenFile(string path, int bufferSize = 1024)
{ ... }
OpenFile(bufferSize: 4096, path: "foo.txt");
與 COM组件互動
[编辑]static void Main(string[] args)
{
Word.Application wordApplication = new Word.Application() { Visible = true };
wordApplication.Documents.Open(@"C:\plant.docx", ReadOnly: true);
}
excelObj.Cells[5, 5].Value = "This is sample text";
泛型的 协变和 逆 变
[编辑]C# 4.0
public interface IComparer<in T>
{
int Compare(T left, T right);
}
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
C# 5.0的 特性
[编辑]- C# Evolution Matrix
- Async Feature (补充: async
和 await是 一 对语法 糖 ,允 许开发人员非常 轻松的 调用基 于TASK的 异步编程)async-await关键字 并不会 真 的 创建一个线程池任务,完成 这个动作依 赖于被 调用方法 中 的 函数 。这一点在 许多C#的中 文教 程 中 被 忽 略 ,导致许多学 习的新手 误以为await关键字 会 直接 创建一个新的线程池任务。 - Caller Information
C# 6.0的 特性
[编辑]唯 讀 Auto屬性 - Auto
屬性 初 始 設定 式 使用 靜態 - Null -
條件 運算 子 字 串 插值例外 狀況 篩 選 條件 - nameof
運算 式 - Catch
和 Finally區 塊 中 的 Await 索引 初 始 設定 式 集合 初 始 設定 式 的 擴充 方法 改 進 的 多 載 解析
表 达式主体 (Expression-bodied)用 于类的 方法 和 只 读属性
[编辑]using System;
public class Person
{
public Person(string firstName, string lastName)
{
fname = firstName;
lname = lastName;
}
private string fname;
private string lname;
public override string ToString() => $"{fname} {lname}".Trim(); //返 回 值类型 string
public void DisplayName() => Console.WriteLine(ToString()); //返 回 值类型 void
public string Name => $"{fname} {lname}".Trim();//只 读属性
}
C# 7.0的 特性
[编辑]out 變數
[编辑]弃元
[编辑]
var tuple = (1, 2, 3, 4, 5);
(_, _, _, _, var fifth) = tuple;
var obj = CultureInfo.CurrentCulture.DateTimeFormat;
switch (obj)
{
case IFormatProvider fmt:
Console.WriteLine($"{fmt} object");
break;
case null:
Console.Write("A null object reference");
break;
case object _:
Console.WriteLine("Some object type without format information");
break;
}
if (obj is object _) { ... }
对
var point = new Point(10, 10);
// 只 要 x, 不 关心 y
point.GetCoordinates(out int x, out _);
void Test(Dto dto)
{
_ = dto ?? throw new ArgumentNullException(nameof(dto));
}
表 达式主体 (Expression-bodied)用 于类的 属性 、构造器 、终结器 、索引 器
[编辑]using System;
public class Location
{
private string locationName;
public Location(string name) => Name = name; //构造函数
public string Name
{
get => locationName; //get属性
set => locationName = value; //set属性
}
public override string ToString() => GetType().Name;
~Location() => Console.WriteLine($"The {ToString()} finalizer is executing."); //析构函数
private string[] types = { "Baseball", "Basketball", "Football",
"Hockey", "Soccer", "Tennis",
"Volleyball" };
public string this[int i]
{
get => types[i]; //索引 器
set => types[i] = value;
}
}
C# 7.1的 特性
[编辑]- async``Main
方法 - default
常 值運算式 推斷 的 tuple項目 名稱
C# 7.2的 特性
[编辑]具備 實 值型別 的 參考 語意 無 後 置 具 名 引數 數 值常值中的 前 置 底 線 - private protected
存 取 修飾 詞
C# 8.0的 特性
[编辑]可 空 引用 类型- await yield return
可 异步返 回 的 迭代器 - Index
索引 类型和 Range区 间类型 允 许在声明 接 口 时为接 口 成 员提供 默 认实现- 递归
的 模 式 匹 配 表 达式形式 的 Switch关键字 在 编译器 可 做类型 推断 的 情 况下,允 许进一 步 省略 类型声明
C# 9的 特性
[编辑]新 的 「Record」類型
[编辑]记录类型,
- 优点:记录类型
是 轻量级的不可 变类型 ,可 以减少 大量 的 代 码,可 以按照 结构和 引用 进行比 较; 缺点 :需要 实例化 大量 的 对象;
// 默 认不可 变的记录类型
public record Person(string Name, int Age);
// 可 变记录类型
public record MutablePerson(string Name, int Age)
{
public string Name { get; set; } = Name;
public int Age { get; set; } = Age;
}
var person1 = new Person("Alice", 40);
var person2 = new Person("Alice", 40);
Console.WriteLine(person1 == person2); // True 结构相 同
Console.WriteLine(person1.Equals(person2)); // True 结构相 同
Console.WriteLine(ReferenceEquals(person1, person2)); // False, 引用 不同
// 改 变默认的记录! --> 创建一 个新的 记录。
var person3 = person1 with { Age = 43 };
Console.WriteLine(person3 == person1); // False 结构不同
// 解 构 (Destruct) 一 个记录, 将 记录的 属性 提 取 为本地 变量
var (name, age) = person3;
var person4 = new MutablePerson("Alice", 40);
person4.Age = 43;
// 记录类型也可以被继承
public record Citizen(string Name, int Age, string Country) : Person(Name, Age);
var citizen = new Citizen("Alice", 40, "China");
Console.WriteLine(person1 == citizen); // False 类型不同 ;
「init」存 取 子
[编辑]init
Student
StudentName
StudentID
public class Student
{
public Student()
{
}
public Student(string studentName,string studentID)
{
StudentName = studentName;
StudentID = studentID;
}
public string StudentName { get; init; } = "Default Name";
public string StudentID { get; init; } = "00000000";
}
如果
Student DemoStudent = new Student();
DemoStudent.StudentName = "Test Name";
而如
Student DemoStudent = new Student() //物件 初 始 化 運算 式
{
StudentName = "Test Name";
StudentID = "0001"
};
Student DemoStudent = new Student("Test Name","0001"); //藉由類型 的 建 構式初 始 化 StudentName以及StudentID。
最 上層 陳述 式 或 称 顶级语句
[编辑]using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
using System;
Console.WriteLine("Hello World!");
//或 者 简化为一 行 语句:
System.Console.WriteLine("Hello World!");
lambda弃元参 数
[编辑]Func<int, int, int> zero = (_, _) => 0;
Func<int, int, int> func = delegate (int _, int _) { return 0; };
只 能 初 始 化 的 设置器
[编辑]Init only setters,
public class InitDemo
{
public string Start { get; init; }
public string Stop { get; init; }
}
// initDemo.Start = "Now"; // Error
// initDemo.End = "Tomorrow"; // Error
var initDemo = new InitDemo
{
Start = "Now",
Stop = "Tomorrow"
};
函数 指 针
[编辑]unsafe class FunctionPointer {
static int GetLength(string s) => s.Length;
delegate*<string, int> functionPointer = &GetLength;
}
public void Test() {
Console.WriteLine(functionPointer("test")); // 4;
}
跳 过本地 初 始 化
[编辑][System.Runtime.CompilerServices.SkipLocalsInit]
static unsafe void DemoLocalsInit() {
int x;
// 注意 , x 没 有 初 始 化 , 输出结果不 确定;
Console.WriteLine(*&x);
}
原生 整数 类型
[编辑]两个
协变返 回 类型
[编辑]
协变
class Person
{
public virtual Person GetPerson() { return new Person(); }
}
class Student : Person
{
public override Student GetPerson() { return new Student(); }
}
模 块初始 化 代 码
[编辑]ModuleInitializerAttribute 为组
- 必须
是 静 态的、无参数 的 、无返回 值的方法 ; 不能 是 范型方法 ,也不能 包含 在 范型类中;不能 是 私有 函数 ,必须是 公 开 (public)或 者 内部 (internal)的 函数 ;
静 态 lambda 表 达式
[编辑]static
分部 方法 扩展
[编辑]- 必须
具有 void返 回 类型。 不能 具有 out参 数 。不能 具有 任 何 可 访问性 (隐式 private )。
初 始 化 表 达式的 简化
[编辑]如果创建对象
Point p = new(1, 1);
Dictionary<string, int> dict = new();
Point[] points = { new(1, 1), new (2, 2), new (3, 3) };
var list = new List<Point> { new(1, 1), new(2, 2), new(3, 3)};
在 本地 函数 上 添加 标记
[编辑]using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace CoreApp2
{
class Program
{
static void Main(string[] args)
{
[Conditional("DEBUG")]
static void DoSomething([NotNull] string test)
{
System.Console.WriteLine("Do it!");
}
DoSomething("Doing!");
}
}
}
GetEnumerator 扩展
[编辑]using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace CoreApp2
{
public static class Extensions
{
public static IEnumerator<T> GetEnumerator<T>(this IEnumerator<T> enumerator) => enumerator;
}
class Program
{
static void Main(string[] args)
{
IEnumerator<string> enumerator = new Collection<string> {"A", "B", "C"}.GetEnumerator();
foreach (var item in enumerator)
{
Console.WriteLine(item);
}
}
}
}
模 式 匹 配 增强
[编辑]Type patterns 类型
object obj = new int();
var type = obj switch
{
string => "string",
int => "int",
_ => "obj"
};
Console.WriteLine(type); // int
Relational patterns 关系
class Person
{
public string name;
public int age;
public Person(string a, int b) { name = a;age = b; }
public void Deconstruct(out string a,out int b){a = name;b = age; }
}
class Program
{
static void Main(string[] args)
{
var person1 = new Person("Alice", 40);
var inRange = person1 switch
{
(_, < 18) => "less than 18",
(_, > 18) => "greater than 18",
(_, 18) => "18 years old!"
};
Console.WriteLine(inRange); // greater than 18
}
}
Conjunctive and patterns 逻辑
// And pattern
var person1 = new Person("Alice", 40);
var ageInRange = person1 switch
{
(_, < 18) => "less than 18",
("Zhang Zhimin", _) and (_, >= 18) => "Alice is greater than 18"
};
Console.WriteLine(ageInRange); // Alice is greater than 18
Disjunctive or patterns 逻辑析取
// Or pattern
var person1 = new Person("Alice", 40);
var ageInRange = person1 switch
{
(_, < 18) => "less than 18",
(_, 18) or (_, > 18) => "18 or greater"
};
Console.WriteLine(ageInRange); // 18 or greater
Negated not patterns 逻辑
// Not pattern
var person1 = new Person("Alice", 40);
var meOrNot = person1 switch
{
not ("Alice", 40) => "Not me!",
_ => "Me :-)"
};
Console.WriteLine(meOrNot); // Me :-)
Parenthesized patterns 带括
// Parenthesized patterns
var is10 = new IsNumber(true, 10);
var n10 = is10 switch
{
((_, > 1 and < 5) and (_, > 5 and < 9)) or (_, 10) => "10",
_ => "not 10"
};
Console.WriteLine(n10); // 10
C# 10的 特性
[编辑]record struct
[编辑]
record struct Point(int X, int Y);
sealed record ToString 方法
[编辑]struct 无参构造函数
[编辑]无参构造
用 with创建新 的 匿名 类型对象
[编辑]var x = new { A = 1, B = 2 };
var y = x with { A = 3 };
这里 y.A
全局 的 using
[编辑]文 件 范围的 namespace
[编辑]namespace MyNamespace;
常 量 字 符 串 插值
[编辑]const string x = "hello";
const string y = $"{x}, world!";
lambda的 改 进
[编辑]lambda 可 以带 attributes
[编辑]f = [Foo] (x) => x; // 给 lambda 设置
f = [return: Foo] (x) => x; // 给 lambda 返 回 值设置
f = ([Foo] x) => x; // 给 lambda 参 数 设置
指定 返 回 值类型
[编辑]此前 C#
f = int () => 4;
支持 ref 、in 、out 等 修 饰
[编辑]f = ref int (ref int x) => ref x; //返 回 一 个参数 的 引用
头等函数
[编辑]
void Foo() { Console.WriteLine("hello"); }
var x = Foo;
x(); // hello
自然 委 托 类型
[编辑]
lambda
var f = () => 1; // Func<int>
var g = string (int x, string y) => $"{y}{x}"; // Func<int, string, string>
var h = "test".GetHashCode; // Func<int>
CallerArgumentExpression
[编辑]
void Foo(int value, [CallerArgumentExpression("value")] string? expression = null)
{
Console.WriteLine(expression + " = " + value);
}
tuple 的 混合 定 义和使用
[编辑]int y = 0;
(var x, y, var z) = (1, 2, 3);
于是 y 就变
接 口 支持 抽象 静 态方法
[编辑].NET 6
泛型 attribute
[编辑]在 方法 上 指定 AsyncMethodBuilder
[编辑]line 指示 器 支持 行列 和 范围
[编辑]
#line (startLine, startChar) - (endLine, endChar) charOffset "fileName"
// 比 如 #line (1, 1) - (2, 2) 3 "test.cs"
嵌 套属性 模 式 匹 配 改 进
[编辑]if (a is { X: { Y: { Z: 4 } } }) { ... }
现在
if (a is { X.Y.Z: 4 }) { ... }
改 进的字 符 串 插值
[编辑]实现
Source Generator v2
[编辑]泛型属性
[编辑]C# 11 开始System.Attribute
public class GenericAttribute<T> : Attribute { }
静 态接口 方法
[编辑]C# 11 开始
public interface IGetNext<T> where T : IGetNext<T>
{
static abstract T operator ++(T other);
}
无符号 右 移 运算符 >>>
[编辑]>>>
,
泛型数学 支持
[编辑]对泛System
public static TResult Sum<T, TResult>(IEnumerable<T> values)
where T : INumber<T>
where TResult : INumber<TResult>
{
TResult result = TResult.Zero;
foreach (var value in values)
{
result += TResult.Create(value);
}
return result;
}
字 符 串 内 插中的 换行符
[编辑]{
}
原始 字 符 串 文 本
[编辑]"""
开始并以 """
结束,"""
结束,且字"""
var x = 1;
var y = 2;
var code1 = """int i = 0;""";
var code2 = $"""int x = {x};""";
var code3 = $$"""
#include <stdio.h>
int main(void) {
const char *s = "{y} = {{y}}"; // {y} = 2
return 0;
}
""";
Console.WriteLine($"code1:\n{code1}\n");
Console.WriteLine($"code2:\n{code2}\n");
Console.WriteLine($"code3:\n{code3}\n");
UTF-8 字 符 串 字面 量
[编辑]u8
ReadOnlySpan<byte>
[27]:
列 表 模 式
[编辑][
]
int[] numbers = { 1, 2, 3 };
Console.WriteLine(numbers is [1, 2, 3]); // True
Console.WriteLine(numbers is [1, 2, 4]); // False
Console.WriteLine(numbers is [1, 2, 3, 4]); // False
Console.WriteLine(numbers is [0 or 1, <= 2, >= 3]); // True
数 值 IntPtr
和 UIntPtr
[编辑]C# 11 nint
nuint
类型IntPtr
UIntPtr
(C# 9
改 进了方法 组向委 托 的 转换
[编辑]优化Sum
SumMethodGroup
static readonly List<int> Numbers = Enumberable.Range(0, 100).ToList();
public int Sum()
{
return Numbers.Where(x => Filter(x)).Sum(); // <- faster
}
public int SumMethodGroup()
{
return Numbers.Where(Filter).Sum(); // <- slower
}
static bool Filter(int number)
{
return number > 50;
}
程 序 的 执行
[编辑]C#
标准化
[编辑]自由 软件基金 会 的 dotGNU Portable.NET(页面存 档备份,存 于互联网档案 馆)- Mono(页面
存 档备份,存 于互联网档案 馆) - Baltie - C# IDE for children and young Baltie(页面
存 档备份,存 于互联网档案 馆)
示 例
[编辑]C# 的 Hello World程 式
[编辑]using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
实现
[编辑]其他 C# 编译
微 軟的Rotor项目(Rotor Project,目前 稱 為 Shared Source Common Language Infrastructure),提供 了 通用 语言运行库(Common Language Runtime)的 實 作 與 C#編 譯 器 。但 是 Shared Source Common Language Infrastructure在 2006年 的 2.0版 後 就停止 了 。由 Microsoft贊助 的 Mono 项目提供 了 C#編 譯 器 ,它提供 了 一 个开源 C# 编译器 、一 个完整 的 CLI 开源实现,同時 也接近 百分之百地實作了.NET Framework类库。而Mono後來 衍伸出 由 微 軟認可 的 第 三 方 套件Xamarin。- Dot GNU
專 案 (现已停 产)也提供 了 另一 個 自由 版本 的 C#編 譯 器 ,也提供 了 .NET Framework类库的 實 作 。
参考 文献
[编辑]- ^ Announcing C# 12. [2023
年 11月18日 ]. - ^ 2.0 2.1 The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.: dotnet/roslyn. November 13, 2019 [2021-08-16]. (
原始 内容 存 档于2021-02-22) –通 过GitHub. - ^ CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes.: dotnet/coreclr. November 13, 2019 [2021-08-16]. (
原始 内容 存 档于2019-10-14) –通 过GitHub. - ^ Rich Hickey Q&A by Michael Fogus. [2017-01-11].
原始 内容 存 档于2017-01-11. - ^ C# Language Specification (PDF) 4th. Ecma International. June 2006 [2012-01-26]. (
原始 内容 (PDF)存 档于2012-12-02). - ^ 6.0 6.1 Using C# 3.0 from .NET 2.0. Danielmoth.com. 2007-05-13 [2012
年 10月 4日 ]. (原始 内容 存 档于2012-09-29). - ^
存 档副本 . [2018-09-06]. (原始 内容 存 档于2018-01-22). - ^ 8.0 8.1 8.2 8.3
存 档副本 . [2018-09-06]. (原始 内容 存 档于2018-01-22). - ^ 9.0 9.1 What's new in C# 10. docs.microsoft.com. [2021-11-10]. (
原始 内容 存 档于2022-02-08) (美国 英 语). - ^ Visual Studio 2022 version 17.0 Release Notes. docs.microsoft.com. [2022-06-24]. (
原始 内容 存 档于2022-08-06). - ^ DeDiv-VR. Visual Studio 2022 version 17.4 Release Notes. learn.microsoft.com. 2024-06-11 [2024-07-15] (
美国 英 语). - ^ BillWagner. What's new in C# 12. learn.microsoft.com. 2024-06-04 [2024-07-15] (
美国 英 语). - ^ Murphy, Adrian. Visual Studio 17.8 now available!. Visual Studio Blog. 2023-11-14 [2024-07-15] (
美国 英 语). - ^ An Introduction to C# Generics. [2020-09-25]. (
原始 内容 存 档于2019-09-24). - ^ Anonymous Methods (C#). [2008-10-24]. (
原始 内容 存 档于2008-04-17). - ^ Covariance and Contravariance in Delegates (C#). [2008-10-24]. (
原始 内容 存 档于2008-10-12). - ^ Tim Anderson. C# pulling ahead of Java - Lead architect paints rosy C# picture. Reg Developer. The Register. 2006-11-14 [2007-01-20]. (
原始 内容 存 档于2007-01-21). - ^ LINQ. Microsoft MSDN. 2007 [2007-08-13]. (
原始 内容 存 档于2007-01-16) (英 语). - ^ The Mellow Musings of Dr. T : What is a collection?. [2008-10-24]. (
原始 内容 存 档于2008-12-18). - ^ Partial Methods. [2007-10-06]. (
原始 内容 存 档于2007-10-16). - ^
一覽 C# 7.0中 的 新 功 能 . [2016-09-14]. (原始 内容 存 档于2018-10-02). - ^ C# 11
中 的 新 增 功 能 . learn.microsoft.com. [2024-3-19]. (原始 内容 存 档于2024-03-19) (中 文 (中国 大 陆)). - ^
教程 :探索 C# 11功 能 -接 口中 的 静 态虚拟成员. learn.microsoft.com. [2024-3-20]. (原始 内容 存 档于2024-03-19) (中 文 (中国 大 陆)). - ^
位 运算符 和 移 位 运算符 (C#参考 ). learn.microsoft.com. [2024-3-20]. (原始 内容 存 档于2024-03-19) (中 文 (中国 大 陆)). - ^ Preview Features in .NET 6 – Generic Math. devblogs.microsoft.com. [2024-3-20]. (
原始 内容 存 档于2024-02-01) (美国 英 语). - ^ C#
程 序 设计基 础. docs.eesast.com. [2024-3-20]. (原始 内容 存 档于2024-03-19) (中 文 (中国 大 陆)). - ^ Utf8 Strings Literals. learn.microsoft.com. [2024-3-20]. (
原始 内容 存 档于2024-03-04) (美国 英 语). - ^ Introducing C# 11: Numeric IntPtr and UIntPtr. anthonygiretti.com. [2024-3-20]. (
原始 内容 存 档于2023-11-30) (美国 英 语). - ^ C# 11 - Improved Method Group. prographers.com. [2024-3-20]. (
原始 内容 存 档于2023-09-30) (美国 英 语). - ^ 30.0 30.1 The RyuJIT transition is complete!. microsoft.com. June 19, 2018 [July 20, 2021]. (
原始 内容 存 档于July 19, 2019). - ^ Managed Execution Process. microsoft.com. [July 20, 2021]. (
原始 内容 存 档于December 23, 2017). - ^ coreclr/src/jit/. github.com. [July 20, 2021]. (
原始 内容 存 档于January 9, 2019). - ^ C# Guide. docs.microsoft.com. [2017-11-20]. (
原始 内容 存 档于2022-08-13). - ^ 5.0.8. microsoft.com. [July 20, 2021]. (
原始 内容 存 档于April 23, 2020). - ^ Mitigation: New 64-bit JIT Compiler. microsoft.com. [July 20, 2021]. (
原始 内容 存 档于April 5, 2018).
外部 連結
[编辑]- (
英文 )C# Language Specification (MSDN)(页面存 档备份,存 于互联网档案 馆) - (
英文 )ECMA-334 C# Language Specification (.pdf) - (
英文 )ISO/IEC 23270:2003 C# Language Specification(页面存 档备份,存 于互联网档案 馆) - (
英文 )Visual Studio Code(页面存 档备份,存 于互联网档案 馆) - (
英文 )Download .NET(页面存 档备份,存 于互联网档案 馆) - Visual C# .NET
入門 (MSDN)(页面存 档备份,存 于互联网档案 馆) - MCS: Mono C#
編 譯 器 (页面存 档备份,存 于互联网档案 馆) - Visual Studio Community(页面
存 档备份,存 于互联网档案 馆) - Visual C# Logo(页面
存 档备份,存 于互联网档案 馆) - C#
教學 (页面存 档备份,存 于互联网档案 馆) - C#
教材 目錄 (页面存 档备份,存 于互联网档案 馆)
|
|
|