1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9. class Program
  10. {
  11.  
  12. static void Main(string[] args)
  13. {
  14.  
  15. Console.WriteLine("输入姓:");
  16. var lastName = Console.ReadLine();
  17. Console.WriteLine("输入名:");
  18.  
  19. var firstName = Console.ReadLine();
  20. //string format 新写法
  21. var student = new Student(firstName,lastName);
  22.  
  23. Console.WriteLine($"student.ToString(){ student.ToString()}");
  24. Console.WriteLine($"student.FullName{ student.FullName}");
  25.  
  26. Console.WriteLine("C#6.0新特性");
  27.  
  28. student = new Student(null,null);
  29.  
  30. Console.WriteLine($"student.ToString(){ student.ToString()}");
  31. Console.WriteLine($"student.FullName{ student?.FullName}");
  32. Console.WriteLine($"student.Grades{ student.Grades.Count}");
  33.  
  34. //异常过滤
  35. try
  36. {
  37. throw new Exception("测试异常filter");
  38.  
  39. }
  40. catch (Exception e) when( e.Message.Contains("filter"))
  41. {
  42.  
  43. Console.WriteLine(e.Message);
  44. throw;
  45. }
  46. //catch (Exception e) when (e.LogException())
  47. //{
  48. // // This is never reached!
  49. //}
  50.  
  51. Console.WriteLine("C#6.0新特性");
  52.  
  53. Console.ReadKey();
  54.  
  55. }
  56.  
  57. public class Student
  58. {
  59. public string LastName {get;}
  60. public string FirstName { get; }
  61.  
  62. public Student(string firstName, string lastName)
  63. {
  64. LastName = lastName;
  65. FirstName = firstName;
  66. }
  67.  
  68. public void SetName(string firstName, string lastName)
  69. {
  70. //this. LastName = lastName;
  71. //this.FirstName = firstName;
  72. }
  73. //方法表达式
  74. public ICollection<double> Grades { get; } = new List<double>();
  75.  
  76. public string GetFormattedGradePoint() =>
  77. $"Name: {LastName}, {FirstName}. G.P.A: {Grades.Average():F2}";
  78. public override string ToString() => $"{LastName},{FirstName}";
  79.  
  80. public string FullName=> $"{LastName},{FirstName}";
  81. }
  82. }
  83. }

C#6.0 新功能的更多相关文章

  1. VS2015预览版中的C#6.0 新功能(二)

    VS2015预览版中的C#6.0 新功能(一) VS2015预览版中的C#6.0 新功能(三) 自动属性的增强 只读自动属性 以前自动属性必须同时提供setter和getter方法,因而只读属性只能通 ...

  2. VS2015预览版中的C#6.0 新功能(三)

    VS2015预览版中的C#6.0 新功能(一) VS2015预览版中的C#6.0 新功能(二) Using static 使用using StaticClass,你可以访问StaticClass类里的 ...

  3. VS2015预览版中的C#6.0 新功能(一)

    VS2015预览版中的C#6.0 新功能(二) VS2015预览版中的C#6.0 新功能(三) VS2015的预览版在11月12日发布了,下面让我们来看看C#都提供了哪些新的功能. 字符串添写(Str ...

  4. REDGATE SQLPROMPT 6.0新功能

    原文:REDGATE SQLPROMPT 6.0新功能 REDGATE SQLPROMPT 6.0新功能 下载地址:http://files.cnblogs.com/lyhabc/SQLPrompt6 ...

  5. unity5.0新功能-布料、动画系统

    原作者:只待苍霞 这一章讲一下布料系统, 这次的布料系统有很大的改良.Unity4中, 需要对SkinnedMeshRenderer使用SkinnedCloth, 或者对Cloth Renderer使 ...

  6. unity5.0新功能

    原作者 只待苍霞 章节1: 先来两个最关心的新功能, 第一章先讲PBS, 第二章讲光影GI.说到PBS, 首先应该想到的是Unity自带的两个新的Shader, 分别是Standard以及Standa ...

  7. Eviews 9.0新功能——估计方法(ARDL、面板自回归、门限回归)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 9.2 估计功能 eviews9.0下载链接: ...

  8. Redis 4.0新功能介绍

    Redis 的作者 antirez 在三天之前通过博客文章<The first release candidate of Redis 4.0 is out>发布了 Redis 4.0 的第 ...

  9. ASP.NET Core 2.0 新功能汇总

    前言 ASP.NET Core 的变化和发展速度是飞快的,当你发现你还没有掌握 ASP.NET Core 1.0 的时候, 2.0 已经快要发布了,目前 2.0 处于 Preview 1 版本,意味着 ...

  10. drone 1.0 新功能试用以及说明

    drone 1.0 rc 已经发布,新的功能很强大,界面比旧版本更加人性化,和git 的集成也更高了 测试环境准备 试用gogs 做为git 管理工具 docker-compose 文件 versio ...

随机推荐

  1. MySQL存储过程中一直困扰的 の 变量中的@

    在声明变量中CREATE function Get_StrArrayLength ( @str varchar(1024), --要分割的字符串@split varchar(10) --分隔符号)re ...

  2. PS日记一

    shift+alt 从中心开始画圆 PHOTOSHOP是处理位图的软件, 栅格化是将矢量图形如:(Illustrator,或者CoreIDRAW中绘画的图形), 包括文字,这些矢量图文转换(也叫栅格化 ...

  3. 【Codeforces 1083A】The Fair Nut and the Best Path

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们最后要的是一条最长的路径. 这条路径的权值和是所有点的权值和-所有边的权值和且这个值最大. 显然如果我们在某一条边上的累计的权值和< ...

  4. python009 Python3 列表

    Python3 列表序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推.Python有6个序列的内置类型,但最常见的是 ...

  5. 服务器端架构及实战 — C#分享

    简介 此文是我2008年读研究生期间做的C#项目技术分享,给计算机专业学生的一些经验分享. 当时工作2年后读研. 计算机基础了解及介绍 了解计算机的核心课程和大家的理解 二进制的历史和原理 数字逻辑及 ...

  6. bzoj3637 CodeChef SPOJ - QTREE6 Query on a tree VI 题解

    题意: 一棵n个节点的树,节点有黑白两种颜色,初始均为白色.两种操作:1.更改一个节点的颜色;2.询问一个节点所处的颜色相同的联通块的大小. 思路: 1.每个节点记录仅考虑其子树时,假设其为黑色时所处 ...

  7. POJ 3090 坐标系上的视线遮蔽问题

    Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...

  8. python监控tomcat日记文件

    最近写了一个用python监控tomcat日记文件的功能 实现的功能: 监控日记文件中实时过来的记录,统计每分钟各个接口调用次数,统计结果插入oracle #!/usr/bin/python # -* ...

  9. solr相关文章

    Solr集群架构概述及delta-import详细配置 背景 由于项目原因,重新熟悉了下Solr,版本为3.6,搭建了主从Solr服务,并使用DIH从RDBMS数据源增量更新索引. 其实也没什么技术含 ...

  10. 使用微软的 ilasm 和 ildasm 对. net程序进行编译和反编译

    为了保证示例的完整性,请先准备好一个 c#写的 exe 程序,或者可以使用我提供的 exe 程序也可以(很简单,为了测试这里仅生成了一个带按钮的 winform,单击按钮提示弹窗) Test WinF ...