转载 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
目录
最新特性:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Feature XXXXXXXXX
历史特性:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2002.12,包含C# 1.0,C# 1.1,C# 1.2。
2006.06,包含C# 2.0。
2017.12,C# 5.0版本,最新版本。
| Version | Date | .NET Framework | CLR | Visual Studio |
|---|---|---|---|---|
| C# 1.0 | 2002.01 | .NET Framework 1.0 | 1.0 | VS 2002 |
| C# 1.1 C# 1.2 | 2003.10 | .NET Framework 1.1 | 1.1 | VS 2003 |
| C# 2.0 | 2005.11 | .NET Framework 2.0 | 2.0 | VS 2005 |
| C# 3.0 | 2007.11 | .NET Framework 2.0 .NET Framework 3.0 .NET Framework 3.5 | 2.0 | VS 2008 VS 2010 |
| C# 4.0 | 2010.04 | .NET Framework 4 | 4.0 | VS 2010 |
| C# 5.0 | 2012.08 | .NET Framework 4.5 .NET Framework 4.5.1 | 4.0 | VS 2012 VS 2013 |
| C# 6.0 | 2015.07 | .NET Framework 4.6 | 4.0 | VS 2015 |
| C# 7.0 | 2017.03 | .NET Framework 4.6.2 | 4.0 | VS 2017 |
| C# 7.1 | 2017.08 | .NET Framework 4.7 | 4.0 | VS 2017 v15.3 |
| C# 7.2 | 2017.11 | .NET Framework 4.7.1 | 4.0 | VS 2017 v15.5 |
| C# 7.3 | 2018.05 | .NET Framework 4.7.2 | 4.0 | VS 2017 v15.7 |
| C# 8.0 | 2019.10 | .NET Framework 4.8 | 4.0 | VS 2019 v16.3 |
Classes:类,面向对象特性
Structs:结构
Interfaces:接口
Events:事件
Properties:属性,类的成员,提供访问字段的灵活方法。
Delegates:委托,一种引用类型,表示对具有特定参数列表和返回类型的方法的引用,类似于函数指针。
Expressions:表达式
Statements:语句是以分号结尾的单行代码,也可以是语句块中的一系列单行语句。 语句块括在括号 {} 中,并且可以包含嵌套块。
Attributes:特性,为程序代码添加元数据或声明性信息,运行时,通过反射可以访问特性信息。
Literals:字面量,也就是不用通过构造函数来创建值
Dispose in foreach:当 IEnumerator 实现 IDisposable 时,foreach 循环中生成的代码会在 IEnumerator 上调用 Dispose。
foreach over string specialization:foreach上的字符串特化。
Generics:泛型
Partial types:可以将类、结构、接口等类型定义拆分到多个文件中
Anonymous methods:匿名方法
Iterators:迭代器
Nullable types:可为空的值类型
Getter/setter separate accessibility:属性访问控制
Method group conversions (delegates):方法组转换,可以将声明委托代表一组方法,隐式调用
Co- and Contra-variance for delegates and interfaces:协变和逆变能够实现数组类型、委托类型参数的隐式引用转换。 协变保留分配兼容性,逆变则与之相反。
Static classes:静态类
Delegate inference:委托推断,将一个方法的地址传送给一个委托变量,编译器会自动检测委托变量的委托类型,然后根据委托类型创建委托实例,并把方法地址传送给委托的构造函数。
Implicitly typed local variables:隐式类型变量,用var声明的变量
Object and collection initializers:对象和集合初始化器
Auto-Implemented properties:自动属性,自动生成属性方法,声明更简洁。
Anonymous types:匿名类型
Extension methods:扩展方法
Query expressions:查询表达式
Lambda expression:Lambda表达式
Expression trees:表达式树,以树形数据结构表示代码,是一种新数据类型
Partial methods:部分方法
Dynamic binding:动态绑定
Named and optional arguments:命名参数和可选参数
Co- and Contra-variance for generic delegates and interfaces:泛型类型的协变和逆变
Embedded interop types ("NoPIA"):开启嵌入类型信息,增加引用COM组件程序的中立性
Asynchronous methods:异步方法
Caller info attributes:调用方信息特性,被调用时访问调用者的信息
foreach loop was changed to generates a new loop variable rather than closing over the same variable every time:foreach循环生成一组新变量而不是每次都隐藏旧变量
Compiler-as-a-service (Roslyn):用C#编写的C#编译器
Import of static type members into namespace:支持命名空间引入静态成员
Exception filters:异常过滤器
Await in catch/finally blocks:支持在catch/finally语句块使用await语句
Auto property initializers:自动属性初始化
Default values for getter-only properties:设置只带有getter的只读属性的默认值
Expression-bodied members:支持以表达式为主体的成员方法和只读属性
Null propagator (null-conditional operator, succinct null checking):Null条件操作符
String interpolation:字符串插值,产生特定格式字符串的新方法
nameof operator:nameof操作符,返回方法、属性、变量的名称
Dictionary initializer:字典初始化
Out variables:Out变量
Pattern matching:模式匹配,根据对象类型或者其它属性实现方法派发
Tuples:元组
Deconstruction:元组析构函数
Discards:弃元,没有命名的变量,只是占位,后面代码不需要使用其值
Local Functions:局部函数
Binary Literals:二进制字面量
Digit Separators:数字分隔符
Ref returns and locals:引用返回值和局部变量
Generalized async return types:async中使用泛型返回类型
More expression-bodied members:允许构造器、解析器、属性可以使用表达式作为主体
Throw expressions:Throw可以在表达式中使用
Async main:异步main方法
Default expressions:默认文本表达式
Reference assemblies:生成引用程序及
Inferred tuple element names:推断元组元素名称
Pattern-matching with generics:泛型类型参数的模式匹配
Span and ref-like types:Span和类引用类型编译时的安全执行
In parameters and readonly references:针对实参的 in 修饰符和针对方法返回的 ref readonly 修饰符,可以在编写安全高效的代码中详细了解所有这些更改。
Ref conditional:条件 ref 表达式
Non-trailing named arguments:非尾随命名参数
Private protected accessibility:Private Protected 访问修饰符
Digit separator after base specifier:允许0b或者0x开头的数值中带下划线
System.Enum, System.Delegate and unmanaged constraints.
Ref local re-assignment: Ref locals and ref parameters can now be reassigned with the ref assignment operator (= ref).
Stackalloc initializers: Stack-allocated arrays can now be initialized, e.g. Span x = stackalloc[] { 1, 2, 3 };.
Indexing movable fixed buffers: Fixed buffers can be indexed into without first being pinned.
Custom fixed statement: Types that implement a suitable GetPinnableReference can be used in a fixed statement.
Improved overload candidates: Some overload resolution candidates can be ruled out early, thus reducing ambiguities.
Expression variables in initializers and queries: Expression variables like out var and pattern variables are allowed in field initializers, constructor initializers and LINQ queries.
Tuple comparison: Tuples can now be compared with == and !=.
Attributes on backing fields: Allows [field: …] attributes on an auto-implemented property to target its backing field.
Nullable reference types: express nullability intent on reference types with ?, notnull constraint and annotations attributes in APIs, the compiler will use those to try and detect possible null values being dereferenced or passed to unsuitable APIs.
Default interface members: interfaces can now have members with default implementations, as well as static/private/protected/internal members except for state (ie. no fields).
Recursive patterns: positional and property patterns allow testing deeper into an object, and switch expressions allow for testing multiple patterns and producing corresponding results in a compact fashion.
Async streams: await foreach and await using allow for asynchronous enumeration and disposal of IAsyncEnumerable collections and IAsyncDisposable resources, and async-iterator methods allow convenient implementation of such asynchronous streams.
Enhanced using: a using declaration is added with an implicit scope and using statements and declarations allow disposal of ref structs using a pattern.
Ranges and indexes: the i..j syntax allows constructing System.Range instances, the ^k syntax allows constructing System.Index instances, and those can be used to index/slice collections.
Null-coalescing assignment: ??= allows conditionally assigning when the value is null.
Static local functions: local functions modified with static cannot capture this or local variables, and local function parameters now shadow locals in parent scopes.
Unmanaged generic structs: generic struct types that only have unmanaged fields are now considered unmanaged (ie. they satisfy the unmanaged constraint).
Readonly members: individual members can now be marked as readonly to indicate and enforce that they do not modify instance state.
Stackalloc in nested contexts: stackalloc expressions are now allowed in more expression contexts.
Alternative interpolated verbatim strings: @$"..." strings are recognized as interpolated verbatim strings just like $@"...".
Obsolete on property accessors: property accessors can now be individually marked as obsolete.
Records and Pattern-based With-Expression:Records是一种轻量级的不可变类型。
Type Classes:Type Classes允许您在类型上添加一组操作,但不实现它。
Dictionary Literals:字典字面量。
Params Span<T>:允许用params修饰Span<T>。
Allow no-arg constructor and field initializers in struct declarations:结构体允许使用无参构造函数。
Native-Sized Number Types:原生大小的数字类型(nint,nuint,nfloat等)'n'表示native(原生),该特性允许声明一个32位或64位的数据类型,这取决于操作系统的平台类型。
Fixed Sized Buffers:固定大小的缓冲区。
Uft8 string literals:新的字符串类型UTF8String。
Base(T):解决默认接口方法中的覆盖冲突问题。