C# 语言历史版本特性(C# 1.0到C# 7.3汇总更新-2018.5更新)

xiaoxiao2021-02-28  101

历史版本

C#作为微软2000年以后.NET平台开发的当家语言,发展至今具有17年的历史,语言本身具有丰富的特性,微软对其更新支持也十分支持。微软将C#提交给标准组织ECMA,C# 5.0目前是ECMA发布的最新规范,C# 6.0还是草案阶段,C# 7.1是微软当前提供的最新规范。

这里仅仅列个提纲,由于C# 5.0是具有ECMA标准规范的版本,所以选择C# 5.0作为主要版本学习,并专题学习C# 6.0,7.0版本新特性。

C#语言规范GitHub库参见:https://github.com/dotnet/csharplang

C#语言路线图及开发中的特性参见: https://github.com/dotnet/roslyn/blob/master/docs/Language Feature Status.md

语言版本发布时间.NET Framework要求Visual Studio版本C# 1.02002.1.NET Framework 1.0Visual Studio .NET 2002C# 1.1\1.22003.4.NET Framework 1.1Visual Studio .NET 2003C# 2.02005.11.NET Framework 2.0Visual Studio 2005C# 3.02007.11.NET Framework 2.0\3.0\3.5Visual Studio 2008C# 4.02010.4.NET Framework 4.0Visual Studio 2010C# 5.02012.8.NET Framework 4.5Visual Studio 2012\2013C# 6.02015.7.NET Framework 4.6Visual Studio 2015C# 7.02017.3.NET Framework 4.6.2Visual Studio 2017C# 7.12017.6.NET Framework 4.7Visual Studio 2017 v15.3预览版C# 7.22017.11.NET Framework 4.7.1Visual Studio 2017 v15.5C# 7.32018.5.NET Framework 4.7.2Visual Studion 2017 v15.7C# 8.0待发布

C# 1.0 特性

第1个版本,编程语言最基础的特性。

Classes:面向对象特性,支持类类型Structs:结构Interfaces:接口Events:事件Properties:属性,类的成员,提供访问字段的灵活方法Delegates:委托,一种引用类型,表示对具有特定参数列表和返回类型的方法的引用Expressions,Statements,Operators:表达式、语句、操作符Attributes:特性,为程序代码添加元数据或声明性信息,运行时,通过反射可以访问特性信息Literals:字面值(或理解为常量值),区别常量,常量是和变量相对的

C# 2特性 (VS 2005)

Generics:泛型Partial types:分部类型,可以将类、结构、接口等类型定义拆分到多个文件中Anonymous methods:匿名方法Iterators:迭代器Nullable types:可以为Null的类型,该类可以是其它值或者nullGetter/setter separate accessibility:属性访问控制Method group conversions (delegates):方法组转换,可以将声明委托代表一组方法,隐式调用Co- and Contra-variance for delegates and interfaces:委托、接口的协变和逆变Static classes:静态类Delegate inference:委托推断,允许将方法名直接赋给委托变量

C# 3特性 (VS 2008)

Implicitly typed local variables:Object and collection initializers:对象和集合初始化器Auto-Implemented properties:自动属性,自动生成属性方法,声明更简洁Anonymous types:匿名类型Extension methods:扩展方法Query expressions:查询表达式Lambda expression:Lambda表达式Expression trees:表达式树,以树形数据结构表示代码,是一种新数据类型Partial methods:部分方法

C# 4特性 (VS 2010)

Dynamic binding:动态绑定Named and optional arguments:命名参数和可选参数Generic co- and contravariance:泛型的协变和逆变Embedded interop types (“NoPIA”):开启嵌入类型信息,增加引用COM组件程序的中立性

C# 5特性 (VS 2012)

Asynchronous methods:异步方法Caller info attributes:调用方信息特性,调用时访问调用者的信息

C# 6特征 (VS 2015)

Compiler-as-a-service (Roslyn)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:设置只读属性的默认值Expression-bodied members:支持以表达式为主体的成员方法和只读属性Null propagator (null-conditional operator, succinct null checking):Null条件操作符String interpolation:字符串插值,产生特定格式字符串的新方法nameof operator:nameof操作符,返回方法、属性、变量的名称Dictionary initializer:字典初始化

C# 7 特征 (Visual Studio 2017)

Out variables:out变量直接声明,例如可以out in parameterPattern matching:模式匹配,根据对象类型或者其它属性实现方法派发Tuples:元组Deconstruction:元组解析Discards:没有命名的变量,只是占位,后面代码不需要使用其值Local Functions:局部函数Binary Literals:二进制字面量Digit Separators:数字分隔符Ref returns and locals:引用返回值和局部变量Generalized async return types:async中使用泛型返回类型More expression-bodied members:允许构造器、解析器、属性可以使用表达式作为bodyThrow expressions:Throw可以在表达式中使用

C# 7.1 特征 (Visual Studio 2017 version 15.3)

Async main:在main方法用async方式Default expressions:引入新的字面值defaultReference assemblies:Inferred tuple element names:Pattern-matching with generics:

C# 7.2 特征 (Visual Studio 2017 version 15.5)

Span and ref-like typesIn parameters and readonly referencesRef conditionalNon-trailing named argumentsPrivate protected accessibilityDigit separator after base specifier

C# 7.3 (Visual Studio 2017 version 15.7)

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.
转载请注明原文地址: https://www.6miu.com/read-47721.html

最新回复(0)