C# 6.0 Feature list

本文介绍了C#中新增的多种语法特性,包括自动属性初始化、仅获取属性、结构体的无参数构造函数、静态成员使用、字典初始化、异步方法在catch/finally块中的使用等,并探讨了这些特性如何简化开发流程。
FeatureExampleC#VB
Auto-property initializerspublic int X { get; set; } = x;AddedExists
Getter-only auto-propertiespublic int Y { get; } = y;AddedAdded
Ctor assignment to getter-only autopropsY = 15AddedAdded
Parameterless struct ctorsStructure S : Sub New() : End Sub : End StructureAddedAdded
Using static membersusing System.Console; … Write(4);AddedExists
Dictionary initializernew JObject { ["x"] = 3, ["y"] = 7 }AddedNo
Await in catch/finallytry … catch { await … } finally { await … }AddedNo
Exception filterscatch(E e) if (e.Count > 5) { … }AddedExists
Partial modulesPartial Module M1N/AAdded
Partial interfacesPartial Interface I1ExistsAdded
Multiline string literals"Hello<newline>World"ExistsAdded
Year-first date literalsDim d = #2014-04-03#N/AAdded
Line continuation commentsDim addrs = From c in Customers ' commentN/AAdded
TypeOf IsNotIf TypeOf x IsNot Customer Then …N/AAdded
Expression-bodied memberspublic double Dist => Sqrt(X * X + Y * Y);AddedNo
Null propagationcustomer?.Orders?[5]?.$priceAddedAdded
String interpolation$"{p.First} {p.Lastis {p.Ageyears old."Added*Planned
nameof operatorstring s = nameof(Console.Write);Added*Planned
#pragma#Disable Warning BC40008AddedAdded
Smart name resolution N/AAdded
ReadWrite props can implement ReadOnly ExistsAdded
#region inside methods ExistsAdded
Overloads inferred from Overrides N/AAdded
CObj in attributes ExistsAdded
CRef and parameter name ExistsAdded
Extension Add in collection initializers AddedExists
Improved overload resolution AddedN/A

转载于:https://www.cnblogs.com/guangfengli/p/5580484.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值