C# 版本历史
C#最初是在2002年随.NET Framework 1.0引入的,此后不断进步发展。 下表列出了每个版本的 C# 中引入的重要功能:
| 版本 | .Net Framework | Visual Studio | 重要的功能 |
|---|---|---|---|
| C# 1.0 | .NET Framework 1.0/1.1 | Visual Studio .NET 2002 | 类 class <br />结构 struct<br />接口 interface<br />事件 event<br />属性 property<br /> 委托 Delegate<br />运算符和表达式 Operator and expression <br />语句 statements,<br /> 特性 Attribute |
| C# 2.0 | .NET Framework 2.0 | Visual Studio 2005 | 泛型 Generics <br />部分类 Partial types <br />匿名方法 Anonymous methods <br />迭代器 Iterators <br />可空类型 Nullable types <br /> 属性 可配置 private Private getter/setter (properties) <br />方法组转换 Method group conversions (delegates) <br />协变和逆变 Covariance and Contra-variance <br />静态类 Static classes |
| C# 3.0 | .NET Framework 3.0\3.5 | Visual Studio 2008 | var 隐式类型本地变量 Implicitly typed local variables<br /> 对象和集合初始始设定 Object and collection initializers <br /> 自动实现属性 Auto-Implemented properties<br /> 匿名类型 Anonymous types<br />扩展方法 Extension methods<br />查询表达式 linq Query expressions<br />Lambda表达式 Lambda expressions<br />表达式树 Expression trees<br />部分方法 Partial Methods |
| C# 4.0 | .NET Framework 4.0 | Visual Studio 2010 | 动态绑定 Dynamic binding (late binding)<br />命名参数 可选参数 Named and optional arguments<br />泛型协变和逆变 Generic co- and contravariance<br />嵌入的互操作类型 Embedded interop types |
| C# 5.0 | .NET Framework 4.5 | Visual Studio 2012/2013 | 异步编程 Async features<br />调用方信息 Caller information |
| C# 6.0 | .NET Framework 4.6 | Visual Studio 2013/2015 | 静态导入 Static imports <br />异常筛选器 Exception Filter when<br />自动属性初始化 Auto-property initializer<br /> 表达式主体定义表达式主体定义 Expression Bodied Methods<br />Null 传播器 Null propagator?. 和 ?[]<br /> nameof 运算符 nameof operator <br />字符串内插 String Interpolation<br />Catch/Finally 块中的 Await Await in catch block<br /> |
| C# 7.0 | .NET Core 2.0 | Visual Studio 2017 | out 变量 out variables<br />元组和析构函数 Tuples and deconstruction<br />模式匹配 Pattern Matching<br />本地函数 Local functions<br /> 弃元 discard<br> more.. |
| C# 8.0 | .NET Core 3.0 | Visual Studio 2019 | 只读成员 Readonly members<br />默认接口方法 Default interface methods<br />using 声明 Using declarations<br />静态本地函数 Static local functions<br />可处置的 ref 结构 Disposable ref structs<br />可空引用类型 Nullable reference types<br /> 异步流 async stream<br> 索引和范围 index and range words[1..4]<br/> ??= null合并赋值 <br/> more.. |
| C# 9.0 | .NET 5.0 | Visual Studio 2019 | Record 类型 <br /> 仅限初始化的设置 init only setters <br/>new(), fit and finish features <br/>支持代码生成器 support for code generators |
| C# 10.0 | .NET 6.0 | Visual Studio 2022 | Source Generator v2 <br /> 泛型Attribute <br /> CallerArgumentExpression <br /> Lambda 支持 Attribute, 支持指定返回类型, 支持 ref 、in 、out <br /> namespace 不用大括号 |
在下一节中了解如何为 C# 设置开发环境。
参考文档 https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-version-history
