平时我们用的 C# 只能看到 .NET 6 .NET8 .NET9 之类的,还有 .Net Framework ,那么他们对应的 C# 版本是什么呢?下面展示一些 C# 版本相关的资料
Target | Version | C# version |
---|---|---|
.NET | 10.x | C# 14 |
.NET | 9.x | C# 13 |
.NET | 8.x | C# 12 |
.NET | 7.x | C# 11 |
.NET | 6.x | C# 10 |
.NET | 5.x | C# 9.0 |
.NET Core | 3.x | C# 8.0 |
.NET Core | 2.x | C# 7.3 |
.NET Standard | 2.1 | C# 8.0 |
.NET Standard | 2.0 | C# 7.3 |
.NET Standard | 1.x | C# 7.3 |
.NET Framework | all | C# 7.3 |
.Net Framework
.NET Framework 版本 | C# 版本 | 出版/发布年份 |
---|---|---|
1.0 | C# 1.0 | 2002 |
1.1 | C# 1.2 | 2003 |
2.0 | C# 2.0 | 2005 |
3.0 / 3.5 | C# 3.0 | 2007 |
4.0 | C# 4.0 | 2010 |
4.5 | C# 5.0 | 2012 |
4.6 | C# 6.0 | 2015 |
4.7 | C# 7.0 | 2017 |
4.7.1 | C# 7.1 | 2017 |
4.7.2 | C# 7.3 | 2018 |
4.8 | C# 7.3 | 2019 |
4.8.1 | C# 7.3 | 2022 |
.NET 更新功能介绍
C# 1.0 released with .NET 1.0 and VS2002 (January 2002)
C# 1.2 (bizarrely enough); released with .NET 1.1 and VS2003 (April 2003). First version to call Dispose on IEnumerators which implemented IDisposable. A few other small features.
C# 2.0 released with .NET 2.0 and VS2005 (November 2005). Major new features: generics, anonymous methods, nullable types, and iterator blocks
C# 3.0 released with .NET 3.5 and VS2008 (November 2007). Major new features: lambda expressions, extension methods, expression trees, anonymous types, implicit typing (var), and query expressions
C# 4.0 released with .NET 4 and VS2010 (April 2010). Major new features: late binding (dynamic), delegate and interface generic variance, more COM support, named arguments, tuple data type and optional parameters
C# 5.0 released with .NET 4.5 and VS2012 (August 2012). Major features: async programming, and caller info attributes. Breaking change: loop variable closure.
C# 6.0 released with .NET 4.6 and VS2015 (July 2015). Implemented by Roslyn. Features: initializers for automatically implemented properties, using directives to import static members, exception filters, element initializers, await in catch and finally, extension Add methods in collection initializers.
C# 7.0 released with .NET 4.7 and VS2017 (March 2017). Major new features: tuples, ref locals and ref return, pattern matching (including pattern-based switch statements), inline out parameter declarations, local functions, binary literals, digit separators, and arbitrary async returns.
C# 7.1 released with VS2017 v15.3 (August 2017). New features: async main, tuple member name inference, default expression, and pattern matching with generics.
C# 7.2 released with VS2017 v15.5 (November 2017). New features: private protected access modifier, Span<T>, aka interior pointer, aka stackonly struct, and everything else.
C# 7.3 released with VS2017 v15.7 (May 2018). New features: enum, delegate and unmanaged generic type constraints. ref reassignment. Unsafe improvements: stackalloc initialization, unpinned indexed fixed buffers, custom fixed statements. Improved overloading resolution. Expression variables in initializers and queries. == and != defined for tuples. Auto-properties' backing fields can now be targeted by attributes.
C# 8.0 released with .NET Core 3.0 and VS2019 v16.3 (September 2019). Major new features: nullable reference-types, asynchronous streams, indices and ranges, readonly members, using declarations, default interface methods, static local functions, and enhancement of interpolated verbatim strings.
C# 9 released with .NET 5.0 and VS2019 v16.8 (November 2020). Major new features: init-only properties, records, with-expressions, data classes, positional records, top-level programs, improved pattern matching (simple type patterns, relational patterns, logical patterns), improved target typing (target-type new expressions, target typed ?? and ?), and covariant returns. Minor features: relax ordering of ref and partial modifiers, parameter null checking, lambda discard parameters, native ints, attributes on local functions, function pointers, static lambdas, extension GetEnumerator, module initializers, and extending partial.
C# 10 released with .NET 6.0 (November 2021). Major new features: record structs, struct parameterless constructors, interpolated string handlers, global using directives, file-scoped namespace declarations, extended property patterns, const interpolated strings, mixed assignment and declaration in deconstruction, async method builders (via attributes) for individual methods, the CallerArgumentExpression attribute for parameters, enhanced #line pragmas.
C# 11 released with .NET 7.0 (November 2022). Major new features: file-scoped types, generic math support, auto-default structs, pattern match Span<char> on a constant string, extended nameof scope, numeric IntPtr, UTF-8 string literals, required members, ref fields and scoped ref, raw string literals, improved method group conversion to delegate, warning wave 7, generic attributes, newlines in string interpolation expressions, list patterns
C# 12 released with .NET 8.0 (November 2023). Major new features: primary constructors, collection expressions, inline arrays, optional parameters in lambda expressions, ref readonly parameters, alias any type, Experimental attribute, interceptors
C# 13 releasing with .NET 9.0 (November 2024). Major new features: params collections, new Lock type and semantics, new Escape sequence \e, method group natural type improvements, implicit indexer access in object initializers, ref locals and unsafe contexts in iterators and async methods, ref struct types to can implement interfaces, partial properties and indexers, ref struct types, overload resolution priority
翻译:
C# 1.0 发布于 .NET 1.0 和 VS2002(2002年1月)
C# 1.2(奇怪的是);发布于 .NET 1.1 和 VS2003(2003年4月)。首次在实现了 IDisposable
的 IEnumerable
上调用 Dispose
。还有一些小功能。
C# 2.0 发布于 .NET 2.0 和 VS2005(2005年11月)。重大新特性:泛型、匿名方法、可空类型和迭代器块。
C# 3.0 发布于 .NET 3.5 和 VS2008(2007年11月)。重大新特性:lambda 表达式、扩展方法、表达式树、匿名类型、隐式类型(var
)和查询表达式。
C# 4.0 发布于 .NET 4 和 VS2010(2010年4月)。重大新特性:动态绑定(dynamic
)、委托和接口的泛型协变、更多的 COM 支持、命名参数、元组数据类型和可选参数。
C# 5.0 发布于 .NET 4.5 和 VS2012(2012年8月)。重大特性:异步编程和调用者信息特性。重大变更:循环变量闭包。
C# 6.0 发布于 .NET 4.6 和 VS2015(2015年7月)。由 Roslyn 实现。特性:自动实现属性的初始化器、使用指令导入静态成员、异常过滤器、元素初始化器、catch
和 finally
中的 await
、集合初始化器中的扩展 Add
方法。
C# 7.0 发布于 .NET 4.7 和 VS2017(2017年3月)。重大新特性:元组、引用局部变量和引用返回、模式匹配(包括基于模式的 switch
语句)、内联 out
参数声明、局部函数、二进制字面量、数字分隔符和任意异步返回。
C# 7.1 发布于 VS2017 v15.3(2017年8月)。新特性:异步主方法、元组成员名推断、默认表达式和带有泛型的模式匹配。
C# 7.2 发布于 VS2017 v15.5(2017年11月)。新特性:私有保护访问修饰符、Span<T>
(也称为内存指针、栈上结构)及其他功能。
C# 7.3 发布于 VS2017 v15.7(2018年5月)。新特性:枚举、委托和无管理泛型类型约束,ref
重新赋值,unsafe
改进:stackalloc
初始化、未固定的索引固定缓冲区、自定义固定语句。改进的重载解析。表达式变量在初始化器和查询中的使用。元组的 ==
和 !=
定义。自动属性的后台字段现在可以通过属性进行标注。
C# 8.0 发布于 .NET Core 3.0 和 VS2019 v16.3(2019年9月)。重大新特性:可空引用类型、异步流、索引和范围、只读成员、使用声明、默认接口方法、静态局部函数和插值原始字符串的增强。
C# 9 发布于 .NET 5.0 和 VS2019 v16.8(2020年11月)。重大新特性:init
仅属性、记录类型、with
表达式、数据类、位置记录、顶级程序、改进的模式匹配(简单类型模式、关系模式、逻辑模式)、改进的目标类型(目标类型 new
表达式、目标类型 ??
和 ?
)、协变返回。次要特性:放宽 ref
和 partial
修饰符的顺序、参数 null 检查、lambda 丢弃参数、本机整数、本地函数上的属性、函数指针、静态 lambda 表达式、扩展 GetEnumerator
、模块初始化器、扩展 partial
。
C# 10 发布于 .NET 6.0(2021年11月)。重大新特性:记录结构、结构体无参构造函数、插值字符串处理器、全局使用声明、文件范围的命名空间声明、扩展的属性模式、常量插值字符串、解构中的混合赋值和声明、异步方法生成器(通过属性)为单独的方法、参数的 CallerArgumentExpression
特性、增强的 #line
指令。
C# 11 发布于 .NET 7.0(2022年11月)。重大新特性:文件作用域类型、泛型数学支持、自动默认结构体、在常量字符串上进行模式匹配 Span<char>
、扩展 nameof
范围、数字 IntPtr
、UTF-8 字符串字面量、必需成员、引用字段和作用域引用、原始字符串字面量、改进的方法组转换为委托、警告波 7、泛型属性、新行字符串插值表达式、列表模式。
C# 12 发布于 .NET 8.0(2023年11月)。重大新特性:主构造函数、集合表达式、内联数组、lambda 表达式中的可选参数、只读引用参数、别名任意类型、实验性特性、拦截器。
C# 13 将发布于 .NET 9.0(2024年11月)。重大新特性:params
集合、新的锁类型和语义、新的转义序列 \e
、方法组自然类型改进、对象初始化器中的隐式索引器访问、迭代器和异步方法中的 ref
局部和 unsafe
上下文、ref
结构体类型可以实现接口、部分属性和索引器、ref
结构体类型、重载解析优先级。
end