C#語言特性

摘自網絡git

 

C# 1.0 特性express

第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的類型,該類能夠是其它值或者null
  • Getter/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)async

  • 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 parameter
  • Pattern matching:模式匹配,根據對象類型或者其它屬性實現方法派發
  • Tuples:元組
  • Deconstruction:元組解析
  • Discards:沒有命名的變量,只是佔位,後面代碼不須要使用其值
  • Local Functions:局部函數
  • Binary Literals:二進制字面量
  • Digit Separators:數字分隔符
  • Ref returns and locals:引用返回值和局部變量
  • Generalized async return types:async中使用泛型返回類型
  • More expression-bodied members:容許構造器、解析器、屬性能夠使用表達式做爲body
  • Throw expressions:Throw能夠在表達式中使用

C# 7.1 特徵 (Visual Studio 2017 version 15.3)spa

  • Async main:在main方法用async方式
  • Default expressions:引入新的字面值default
  • Reference assemblies:
  • Inferred tuple element names:
  • Pattern-matching with generics:
相關文章
相關標籤/搜索