据扯,C# 6.0在不远的将来就发布了,对应的IDE可能是VS 2014(.Net Framework 5.0),因为VS 2013已于2013年10月份发布了,对应的是.Net Franework 4.5.1。

从Visual Studio的更新规律上来看,微软2或者3年,更新增加的东西会比较多,所以对于C# 6.0,还是有一些期待的。

下面这张图列出了C#每次重要更新的时间及增加的新特性,对于了解C#这些年的发展历程,对C#的认识更加全面,是有帮助的。其中图的最后一行C#6.0是根据一些博客整理的,如有错误,随时改正。

C# 6.0可能的新特性

1、主构造函数(Primary Constructors)

主构造函数给类中的变量赋值

Before

public class Point {
private int x, y; public Point(int x, int y)
this.x = x;
this.y = y;
}
}

After

public class Point(int x, int y) {
private int x, y;
}

2、自动属性赋值(Auto Properties)

Before

  class Point
{
public int X { get; private set; }
public int Y { get; private set; } public Point()
{
this.X = ;
this.Y = ;
}
}

After

  class Point
{
public int X { get; private set; } = ;
public int Y { get; private set; } = ;
}

3、using静态类(Static type using statements;)

using会把引用类的所有静态方法导入到当前命名空间

Before

public double A { get { return Math.Sqrt(Math.Round(5.142)); } }

After

using System.Math;
...
public double A { get { return Sqrt(Round(5.142)); } }

4、Property Expressions

Before

public double Distance {
get { return Math.Sqrt((X * X) + (Y * Y)); }
}

After

public double Distance => Math.Sqrt((X * X) + (Y * Y));

初看起来像Lambda表达式,其实和Lambda无关系。

5. Method Expressions

Before

public Point Move(int dx, int dy) {
return new Point(X + dx1, Y + dy1);
}

After

public Point Move(int dx, int dy) => new Point(X + dx, Y + dy);

这个和Property Expressions类似

6、Params for enumerables

Before

Do(someEnum.ToArray());
...
public void Do(params int[] values) { ... }

After

Do(someEnum);
public void Do(params IEnumerable<Point> points) { ... }

以前params是只可以修饰array类型的参数,现在多了一些类型

7、Monadic null checking(null检查运算符)

Before

if (points != null) {
var next = points.FirstOrDefault();
if (next != null && next.X != null) return next.X;
}
return -;

After

var bestValue = points?.FirstOrDefault()?.X ?? -;

这个少了好几行代码,赞啊

8、Constructor type parameter inference

Before

var x = MyClass.Create(, "X");
...
public MyClass<T1, T2> Create<T1, T2>(T1 a, T2 b) {
return new MyClass<T1, T2>(a, b);
}

After

var x = new MyClass(, "X");

9、 Inline declarations for out params(内联out参数定义)

Before

int x;
int.TryParse("", out x);

After

int.TryParse("", out int x);

说实话,这个很常用。

当然,C# 6.0的全部新特性不止这么多,限于篇幅,就整理这些,若想了解更多,请参考下面的链接。

参考资料:

http://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation

http://en.wikipedia.org/wiki/.NET_Framework_version_history

http://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated

http://www.kunal-chowdhury.com/2012/07/evolution-of-c-10-50-what-are-new.html

http://www.cnblogs.com/TianFang/p/3647144.html

C# 6.0可能的新特性及C#发展历程的更多相关文章

  1. C# 6.0可能的新特性及C#发展历程[转]

      C# 6.0可能的新特性及C#发展历程[转] 年10月份发布了,对应的是.Net Franework 4.5.1. 或者3年,更新增加的东西会比较多,所以对于C# 6.0,还是有一些期待的. 下面 ...

  2. 转载——C# 6.0可能的新特性及C#发展历程

    据扯,C# 6.0在不远的将来就发布了,对应的IDE可能是VS 2014(.Net Framework 5.0),因为VS 2013已于2013年10月份发布了,对应的是.Net Franework ...

  3. 有史来最大改变 Android 5.0十大新特性

    有史来最大改变 Android 5.0十大新特性 2014.10.16 14:51:31 来源:腾讯数码作者:腾讯数码 ( 0 条评论 )   距离Android系统上一次重大更新不到一年的时间,谷歌 ...

  4. C# 6.0可能的新特性

    C# 6.0可能的新特性 1.主构造函数(Primary Constructors) 主构造函数给类中的变量赋值 Before public class Point { private int x, ...

  5. Spring Boot 2.0正式发布,新特性解读

    作者|翟永超 Spring Boot 2.0 来啦,有哪些新特性?升级吗? 写在前面 北京时间 3 月 1 日,经过漫长的等待之后,Spring Boot 2.0 正式发布.作为 Spring 生态中 ...

  6. MySQL 8.0.2复制新特性(翻译)

    译者:知数堂星耀队 MySQL 8.0.2复制新特性 MySQL 8 正在变得原来越好,而且这也在我们MySQL复制研发团队引起了一阵热潮.我们一直致力于全面提升MySQL复制,通过引入新的和一些有趣 ...

  7. Atitit.c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结

    Atitit.c# .net 3.5 4.0 各个版本新特性战略规划总结 1. --------------.Net Framework版本同CLR版本的关系1 2. paip.----------- ...

  8. c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结【转载】

    引用:http://blog.csdn.net/attilax/article/details/42014327 c# .net 3.5 4.0 各个版本新特性战略规划总结 1. ---------- ...

  9. 【HANA系列】SAP HANA 1.0 SPS 11 新特性

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA 1.0 SPS ...

随机推荐

  1. springMvc3.0.5搭建全程 (转)

    用了大半年的Spring MVC3.0,用着感觉不错.简单写一个搭建Spring MVC3.0的流程(以Spring3.0.5为列),数据库交互使用spring JDBC Template,附件有项目 ...

  2. Android——播放器和图片轮播

    layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  3. SQL增删改语句常用

    创建table: create table tab_name( col1 type; 约束:主键-外键-非空-检查-唯一 col2 type; ); 删除表 : drop table tab_name ...

  4. JS-学习-DOM元素尺寸和位置

    一,获取元素的css大小 1.通过style内联获取元素的大小 var box = document.getElementById('box');    // 获得元素;     box.style. ...

  5. 【总结】matlab求两个序列的相关性

    首先说说自相关和互相关的概念.  自相关 在统计学中的定义,自相关函数就是将一个有序的随机变量系列与其自身作比较.每个不存在相位差的系列,都与其都与其自身相似,即在此情况下,自相关函数值最大. 在信号 ...

  6. python小知识点

    问题:求列表中每个元素的元素次方之和>>> a=[1,2,3,4]>>> k=len(a)第一种解法#    s=0#    for x in a:#        ...

  7. [转]require(),include(),require_once()和include_once()区别

    require(),include(),require_once()和include_once()区别 面试中最容易提到的一个PHP的问题,我想和大家共勉一下: require()和include() ...

  8. C#中的属性太邪恶了

    好懒,啥都不想写了.C#的属性伤透了我的心.只能相信记忆力和想象力能让我下次翻到这篇日志时能瞬间想到我们在谈瓦特. http://stackoverflow.com/questions/1224270 ...

  9. 自己家里搭建NAS服务器有什么好方案?

    转自:https://www.zhihu.com/question/21359049 作者:陈二发链接:https://www.zhihu.com/question/21359049/answer/6 ...

  10. Head First 设计模式之观察者模式(Observer Pattern)

    前言: 这一节开始学习观察者模式,开始讲之前会先像第一节那样通过一个应用场景来引入该模式.具体场景为:气象站提供了一个WeatherData对象,该对象可以追踪获取天气的温度.气压.湿度信息,Weat ...