C# 5.0

VS2012 引入,参见:https://www.cnblogs.com/ctcx/p/5177635.html

调用者信息特性

CallerMemberNameAttribute | CallerFilePathAttribute | CallerLineNumberAttribute

.NET Framework 4.5 中新增,用于请求编译器在编译过程中进行代码的转换 。

使用方式:直接调用即可

public static void TraceMessage(string message, string errCode,
[CallerMemberNameAttribute] string memberName = "",
[CallerFilePathAttribute] string filePath = "",
[CallerLineNumberAttribute] int lineNumber = 0)

若要在 .NET Framework 4.0 中使用,需自定义特性

namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public class CallerMemberNameAttribute : Attribute
{ } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )]
public class CallerFilePathAttribute : Attribute
{ } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )]
public class CallerLineNumberAttribute : Attribute
{ }
}

关键字async和await

简化异步编程,建议首先了解C# 4.0引入的:Task

在Lambda表达式中用循环变量

C#5.0中纠正循环变量覆盖,无须在循环中引入临时变量,直接常规编码即可。

C# 6.0

VS2015 引入,参考:https://www.cnblogs.com/dotnet261010/p/9147707.html

using static

命名空间语法糖,导入静态类

字符串嵌入值 | 空值运算符

$"{表达式|属性字段值}"  //简化string.Format表达式
// null值亦可调用,程序不会报错,也不会输出任何值
string name = null; name?.ToString();

对象初始化器 | 异常过滤器

IDictionary<int, string> dictNew = new Dictionary<int, string>() {
[4] = "first", [5] = "second" //索引方式初始化
};
try {} //满足条件才进入catch
catch (Exception e) when (匹配条件) { }

同时支持在catch和finally中使用await运算符。

nameof表达式

用于变量、函数、类或命名空间,返回其名称,可应用于反射等场景。

属性/方法使用Lambda表达式

public double Distance => Math.Sqrt((X * X) + (Y * Y));
public void Print() => Console.WriteLine(Name);

该功能在C#7.0中已有进一步增强。

C# 7.0

VS2017 引入,参考:https://www.cnblogs.com/cncc/p/7698543.html

模式匹配

[1]. is表达式

[2]. case分支引入类型匹配和条件判断

元组Tuples:强烈推荐

  • ValueTuple支持语义上的字段命名
  • ValueTuple是值类型(Struct)

元组解构:Deconstruct 方法成员(实例或扩展)

// 实例签名
public void Deconstruct(out type variable1, out type variable2...)
// 扩展签名
public static void Deconstruct(this type instance, out type variable1, out type variable2...)

局部函数

本质是 internal 修饰的静态函数

其他重要特性

  • out变量:无需预先声明,内联声明即可
  • ref引用强化:允许获取某个变量(引用类型)的局部引用
  • 数字分割:可以按照一定的位数用“_”进行分割
  • 二进制文本:0b开头二进制串

C# 5.0-.Net新特性的更多相关文章

  1. php5.3到php7.0.x新特性介绍

    <?php /*php5.3*/ echo '<hr>'; const MYTT = 'aaa'; #print_r(get_defined_constants()); /* 5.4 ...

  2. paip.php 5.0 5.3 5.4 5.5 -6.0的新特性总结与比较

    paip.php 5.0 5.3 5.4  5.5 -6.0的新特性总结与比较 PHP5的新特性 2 · 对象的参照过渡是默认的(default) 3 · 引入访问属性的限制 3 · 引入访问方法的限 ...

  3. NodeJS 框架 Express 从 3.0升级至4.0的新特性

    NodeJS 框架 Express 从 3.0升级至4.0的新特性 [原文地址:√https://scotch.io/bar-talk/expressjs-4-0-new-features-and-u ...

  4. 相比于python2.6,python3.0的新特性。

    这篇文章主要介绍了相比于python2.6,python3.0的新特性.更详细的介绍请参见python3.0的文档. Common Stumbling Blocks 本段简单的列出容易使人出错的变动. ...

  5. MySQL 8.0 InnoDB新特性

    MySQL 8.0 InnoDB新特性 1.数据字典全部采用InnoDB引擎存储,支持DDL原子性.crash safe,metadata管理更完善 2.快速在线加新列(腾讯互娱DBA团队贡献) 3. ...

  6. Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性

    Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性 1.1. Jquery1.12  jQuery 2.2 和 1.12 新版本发布 - OPEN资讯.h ...

  7. [PHP] 从PHP 5.6.x 移植到 PHP 7.0.x新特性

    从PHP 5.6.x 移植到 PHP 7.0.x 新特性: 1.标量类型声明 字符串(string), 整数 (int), 浮点数 (float), 布尔值 (bool),callable,array ...

  8. servlet3.0 的新特性之二注解代替了web.xml配置文件

    servlet3.0 的新特性: 注解代替了 web.xml 文件 支持了对异步的处理 对上传文件的支持 1.注解代替了配置文件 1.删除了web.xml 文件 2. 在Servlet类上添加@Web ...

  9. C# 6.0/7.0 的新特性

    转眼C#语言都已经迭代到7.0版本了,很多小伙伴都已经把C# 7.0 的新特性应用到代码中了,想想自己连6.0的新特性都还很少使用,今天特意搜集了一下6.0和7.0的一些新特性,记录一下,方便查阅. ...

  10. C#6.0的新特性之内插字符串

    https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/interpolated-strings C# 6 ...

随机推荐

  1. R 语言安装问题集锦

    R安装问题R CMD INSTALL -l /data1/jhh/envirment/R/R_lib /data1/jhh/software/qvalue_2.10.0.tar.gz 问题1 :con ...

  2. OC和C++混编

    msg->mIntArg0 = PDP_TaskTip; NoticeData* noticeData = GET_SYSTEM(DataSystem)->getNoticeData(); ...

  3. 【Mac】使用QuickTime Player录制屏幕录像

    我门分享都需要用到录屏软件,Mac系统有自带的QuickTime Player软件可以录制屏幕录像 环境与工具 1.mac系统 2.mac自带的QuickTime Player软件 使用方法 1.打开 ...

  4. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...

  5. 2018.08.30 NOIP模拟 wall(模拟)

    [问题描述] 万里长城是中国强大的标志,长城在古代的用途主要用于快速传递军事消息和抵御 外敌,在长城上的烽火台即可以作为藏兵的堡垒有可以来点燃狼烟传递消息. 现在有一段 万里长城,一共有 N 个烽火台 ...

  6. 2018.08.19 洛谷P1402 酒店之王(最大流)

    传送门 最大流入门题,把人拆点即可. 代码: #include<bits/stdc++.h> #define N 505 using namespace std; inline int r ...

  7. idea使用svn提交时出现错误Warning not all local changes may be shown due to an error

    参考于https://www.cnblogs.com/zhujiabin/p/6708012.html 解决方案: 1.File > Settings > Version Control ...

  8. [笔记]python

    配置python apt install python2.7 python3 apt install python-bs4 python3-bs4 apt install virtualenv apt ...

  9. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  10. 使用VSTS进行单元测试练习

    本次作业要求:练习教科书第22~25页单元测试练习,要求自行安装Visual Studio开发平台,版本至少在2010以上,要求把程序安装过程和练习过程写到博客上,越详细越好,要图文并茂,没有书的同学 ...