using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApp2
{
class Program
{ static void Main(string[] args)
{ Console.WriteLine("输入姓:");
var lastName = Console.ReadLine();
Console.WriteLine("输入名:"); var firstName = Console.ReadLine();
//string format 新写法
var student = new Student(firstName,lastName); Console.WriteLine($"student.ToString(){ student.ToString()}");
Console.WriteLine($"student.FullName{ student.FullName}"); Console.WriteLine("C#6.0新特性"); student = new Student(null,null); Console.WriteLine($"student.ToString(){ student.ToString()}");
Console.WriteLine($"student.FullName{ student?.FullName}");
Console.WriteLine($"student.Grades{ student.Grades.Count}"); //异常过滤
try
{
throw new Exception("测试异常filter"); }
catch (Exception e) when( e.Message.Contains("filter"))
{ Console.WriteLine(e.Message);
throw;
}
//catch (Exception e) when (e.LogException())
//{
// // This is never reached!
//} Console.WriteLine("C#6.0新特性"); Console.ReadKey(); } public class Student
{
public string LastName {get;}
public string FirstName { get; } public Student(string firstName, string lastName)
{
LastName = lastName;
FirstName = firstName;
} public void SetName(string firstName, string lastName)
{
//this. LastName = lastName;
//this.FirstName = firstName;
}
//方法表达式
public ICollection<double> Grades { get; } = new List<double>(); public string GetFormattedGradePoint() =>
$"Name: {LastName}, {FirstName}. G.P.A: {Grades.Average():F2}";
public override string ToString() => $"{LastName},{FirstName}"; public string FullName=> $"{LastName},{FirstName}";
}
}
}

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. Java基础学习总结(94)——Java线程再学习

    Java线程有哪些不太为人所知的技巧与用法? 萝卜白菜各有所爱.像我就喜欢Java.学无止境,这也是我喜欢它的一个原因.日常工作中你所用到的工具,通常都有些你从来没有了解过的东西,比方说某个方法或者是 ...

  2. 可编辑div的createRange()

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // 在元素的指定位 ...

  3. 大数据学习——redis安装

    用源码工程来编译安装 / 到官网下载最新stable版 / 解压源码并进入目录 .tar.gz -C ./redis-src/ / make 如果报错提示缺少gcc,则安装gcc : yum inst ...

  4. Back弹出AlertDialog

    package com.pingyijinren.helloworld.activity; import android.content.DialogInterface; import android ...

  5. SGU 104 Little shop of flowers【DP】

    浪(吃)了一天,水道题冷静冷静.... 题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=104 题意: 给定每朵花放在每个花盆的值, ...

  6. Permutation Sequence(超时,排列问题)

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. ZOJ 1232 【灵活运用FLOYD】 【图DP】

    题意: copy自http://blog.csdn.net/monkey_little/article/details/6637805 有A个村子和B个城堡,村子标号是1~A,城堡标号是A+1~B.马 ...

  8. powerDigner使用

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...

  9. 数据库中的DDL/DML/DCL解释(转)

    DDL is Data Definition Language statements. Some examples:数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 1.CREATE - ...

  10. C# 9.0新特性

    CandidateFeaturesForCSharp9 看到标题,是不是认为我把标题写错了?是的,C# 8.0还未正式发布,在官网它的最新版本还是Preview 5,通往C#9的漫长道路却已经开始.前 ...