C#6.0 新功能
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 新功能的更多相关文章
- VS2015预览版中的C#6.0 新功能(二)
VS2015预览版中的C#6.0 新功能(一) VS2015预览版中的C#6.0 新功能(三) 自动属性的增强 只读自动属性 以前自动属性必须同时提供setter和getter方法,因而只读属性只能通 ...
- VS2015预览版中的C#6.0 新功能(三)
VS2015预览版中的C#6.0 新功能(一) VS2015预览版中的C#6.0 新功能(二) Using static 使用using StaticClass,你可以访问StaticClass类里的 ...
- VS2015预览版中的C#6.0 新功能(一)
VS2015预览版中的C#6.0 新功能(二) VS2015预览版中的C#6.0 新功能(三) VS2015的预览版在11月12日发布了,下面让我们来看看C#都提供了哪些新的功能. 字符串添写(Str ...
- REDGATE SQLPROMPT 6.0新功能
原文:REDGATE SQLPROMPT 6.0新功能 REDGATE SQLPROMPT 6.0新功能 下载地址:http://files.cnblogs.com/lyhabc/SQLPrompt6 ...
- unity5.0新功能-布料、动画系统
原作者:只待苍霞 这一章讲一下布料系统, 这次的布料系统有很大的改良.Unity4中, 需要对SkinnedMeshRenderer使用SkinnedCloth, 或者对Cloth Renderer使 ...
- unity5.0新功能
原作者 只待苍霞 章节1: 先来两个最关心的新功能, 第一章先讲PBS, 第二章讲光影GI.说到PBS, 首先应该想到的是Unity自带的两个新的Shader, 分别是Standard以及Standa ...
- Eviews 9.0新功能——估计方法(ARDL、面板自回归、门限回归)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 9.2 估计功能 eviews9.0下载链接: ...
- Redis 4.0新功能介绍
Redis 的作者 antirez 在三天之前通过博客文章<The first release candidate of Redis 4.0 is out>发布了 Redis 4.0 的第 ...
- ASP.NET Core 2.0 新功能汇总
前言 ASP.NET Core 的变化和发展速度是飞快的,当你发现你还没有掌握 ASP.NET Core 1.0 的时候, 2.0 已经快要发布了,目前 2.0 处于 Preview 1 版本,意味着 ...
- drone 1.0 新功能试用以及说明
drone 1.0 rc 已经发布,新的功能很强大,界面比旧版本更加人性化,和git 的集成也更高了 测试环境准备 试用gogs 做为git 管理工具 docker-compose 文件 versio ...
随机推荐
- DOS使用笔记
DOS下cd命令: cd .. 上一级目录: g: 指定当期目录到G盘,而cd g:是没有效果的: 如图: 在安装Windows服务的过程中,如果installutil为64位版本,那么编译生成项目的 ...
- 关于shell中常见功能的实现方式总结
一.shell脚本中连接数据库 二.
- 使用inline-box代替float
在网页布局中,使用float有不少好处,可以为你带来更加自由的布局,还可以自动根据浏览器改变布局效果.但是使用多了你也可能发现有一个问题,使用了float之后,外层的div不会撑高,导致布局出现坍塌. ...
- Run-time Settings--General--Run Logic
LR单用户,重复操作日志 案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录3个脚本?每个事务分别在脚本中复制N次? 当然不用,LR早就想到了你的需求,下面让我们隆重 ...
- [转]ORA-38500: USING CURRENT LOGFILE option not available without stand
标签: oracle 10g 数据库 ora-38500 it 分类: IT author:skate time :2009/08/03 在dataguard启用实时恢复的时候,报如下错误: ORA- ...
- Linux核心参数Shmmax,shmall,shmni
Linux 下核心参数调整 kernel.shmmax shmmax是核心参数中最重要的参数之一,用于定义单个共享内存段的最大值,shmmax设置应足够大,能在一个共享内存段下容纳下整个的SGA,设置 ...
- BZOJ3027 - [CEOI2004]Sweet
Portal Description 给出\(n(n\leq10),a,b(a,b\leq10^7)\)与\(\{c_n\}(c_i\leq10^6)\),求使得\(\sum_{i=1}^n x_i ...
- FastDfs + Dht 搭建笔记
以下为搭建一套分布式文件集群系统,参考了很多资料,自己经过在服务器上搭建并且经过了测试.记录以方便以后使用查看. FastDfs + Dht 安装手册 一:概述 FastDFS是由淘宝的余庆先生所开发 ...
- HDU 1669 二分图多重匹配+二分
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- 洛谷——P2434 [SDOI2005]区间
P2434 [SDOI2005]区间 题目描述 现给定n个闭区间[ai, bi],1<=i<=n.这些区间的并可以表示为一些不相交的闭区间的并.你的任务就是在这些表示方式中找出包含最少区间 ...