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 ...
随机推荐
- 3.3.2 使用 cut 选定字段
cut 命令是用来剪下文本文件里的数据,文本文件可以是字段类型或是字符类型.后一种数据类型在遇到需要从文件里剪下特定的列时,特别方便.请注意:一个制表字符在此被视为单个字符. ...
- 修改centos的yum源为国内的源
1.安装Centos后默认的Yum源如下 ll /etc/yum.repos.d/ [root@localhost ~]# ll /etc/yum.repos.d/ total 32 -rw-r- ...
- 数据库服务器的监控 赛门铁克 Veritas i3 APM 查找指定时间段最耗服务器资源的TopSQL
- BZOJ4553 - [TJOI2016]序列
Portal Description 给出一个\(n(n\leq10^5)\)个数的数列\(\{a_n\}\)和\(m(m\leq10^5)\)个形如\((x,y)\)的变化,表示\(a_x\)可以变 ...
- react.js 父子组件数据绑定实时通讯
import React,{Component} from 'react' import ReactDOM from 'react-dom' class ChildCounter extends Co ...
- [Usaco2006 Nov] Fence Repair 切割木板
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1356 Solved: 714[Submit][Status][Discuss] Description ...
- Codeforces Round #298 (Div. 2) D. Handshakes [贪心]
传送门 D. Handshakes time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- BZOJ 1123 tarjan
题目链接 题意:一张无向图,把第$i$个点关联的所有边去掉,求无向图中有多少个点对不连通. 题解: 如果割的不是割点,那么总答案是$2\times (n-1)$. 如果是割点,要分别考虑每个子树的贡献 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...
- eclipse 修改Java代码 不用重新启动tomcat
例子: 1.在tomcat server.xml文件配置加上这句话: <Context debug="0" docBase="C:\Users\admin\Desk ...