• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#特性-更新到9.0

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

C# Language Design

C# Language Specification

Standard ECMA-334

  • 2002.12,包含C# 1.0,C# 1.1,C# 1.2。
  • 2006.06,包含C# 2.0。
  • 2017.12,C# 5.0版本,最新版本

Microsoft

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

C# Language Feature

C# 1.0 - Visual Studio .NET 2002

  • Classes:类,面向对象特性
  • Structs:结构
  • Interfaces:接口
  • Events:事件
  • Properties:属性,类的成员,提供访问字段的灵活方法。
  • Delegates:委托,一种引用类型,表示对具有特定参数列表和返回类型的方法的引用,类似于函数指针。
  • Expressions:表达式
  • Statements:语句是以分号结尾的单行代码,也可以是语句块中的一系列单行语句。 语句块括在括号 {} 中,并且可以包含嵌套块。
  • Attributes:特性,为程序代码添加元数据或声明性信息,运行时,通过反射可以访问特性信息。
  • Literals:字面量,也就是不用通过构造函数来创建值

C# 1.2 - Visual Studio .NET 2003

  • Dispose in foreach:当 IEnumerator 实现 IDisposable 时,foreach 循环中生成的代码会在 IEnumerator 上调用 Dispose。

  • foreach over string specialization:foreach上的字符串特化。

C# 2.0 - Visual Studio 2005

  • 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:委托推断,将一个方法的地址传送给一个委托变量,编译器会自动检测委托变量的委托类型,然后根据委托类型创建委托实例,并把方法地址传送给委托的构造函数。

C# 3.0 - Visual Studio 2008

C# 4.0 - Visual Studio 2010

C# 5.0 - Visual Studio 2012

  • 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循环生成一组新变量而不是每次都隐藏旧变量

C# 6.0 - Visual Studio 2015

C# 7.0 - Visual Studio 2017

C# 7.1 - Visual Studio 2017 version 15.3

C# 7.2 - Visual Studio 2017 version 15.5

C# 7.3 - Visual Studio 2017 version 15.7

C# 8.0 - .NET Core 3.0 and Visual Studio 2019 version 16.3

  • 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.
  • Permit t is null on unconstrained type parameter

C# 9.0

  • 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):解决默认接口方法中的覆盖冲突问题

Reference


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#批量插入发布时间:2022-07-18
下一篇:
C++标准库简介、与STL的关系。发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap