C# 6.0 (VS2015 CTP6)
/*
C# 6.0 demo
https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14
*/ using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using static System.Console; //C# 6.0: Using static members
using static System.Math; //C# 6.0: Using static members
using static ConsoleApplication1.MyClass; //C# 6.0: Using static members
using static ConsoleApplication1.MyStruct; //C# 6.0: Using static members namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WriteLine("C# 6.0 Demo"); //C# 6.0: Using static members
WriteLine(RefUrl); //C# 6.0: Using static members var dictionary = new JObject {["x"] = 3 }; //C# 6.0: Dictionary initializer
WriteLine("dictionary[\"x\"]: {0}", dictionary["x"]); var myClass = new MyClass();
PrintMyClass(myClass); //C# 6.0: Using static members
myClass.X = 100;
PrintMyClass(myClass); var anotherDist = myClass.AnotherMyClass?.Dist; //C# 6.0: Null propagation
WriteLine("myClass.AnotherMyClass?.Dist: {0}", anotherDist);
// anotherDist == null
//true
//anotherDist > 0
//false
//anotherDist == 0
//false
//anotherDist < 0
//false
//anotherDist = 0
//0
//anotherDist
//0
myClass.AnotherMyClass = new MyClass(y: 0);
anotherDist = myClass.AnotherMyClass?.Dist;
WriteLine("myClass.AnotherMyClass?.Dist: {0}", anotherDist); string s = nameof(Console.Write); //C# 6.0: nameof operator
WriteLine("nameof(Console.Write) = {0}", s); var p = new {Name = "Bob", Age = 30};
WriteLine($"{p.Name} is {p.Age - 10} years old."); //C# 6.0: String interpolation try
{
throw new Exception("hi!");
throw new Exception("wah!");
}
catch (Exception e) when (e.Message == "hi!") //C# 6.0: Exception filters
{
WriteLine("Catch a message is \"hi!\" exception. ");
}
catch (Exception e)
{
WriteLine("Catch other message exception. Message is \"{0}\"", e.Message);
} Write("Press any key to EXIT...");
ReadKey(true);
}
} public struct MyStruct
{
public static string RefUrl = "https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14";
} public class MyClass
{
public int X { get; set; } = 90; //C# 6.0: Auto-property initializers public int Y { get; } = 100; //C# 6.0: Getter-only auto-properties public MyClass(int y)
:this()
{
Y = y; //C# 6.0: Ctor assignment to getter-only autoprops
} public MyClass()
{ } public double Dist => Sqrt(X * X + Y * Y); //C# 6.0: Expression-bodied members public MyClass AnotherMyClass { get; set; } public static void PrintMyClass(MyClass myClass)
{
WriteLine($"PrintMyClass: X = {myClass.X}, Y = {myClass.Y}, Dist = sqrt(x*x+y*y) = {myClass.Dist}");
}
} }
结果:
C# 6.0 Demo
https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14
dictionary["x"]: 3
PrintMyClass: X = 90, Y = 100, Dist = sqrt(x*x+y*y) = 134.536240470737
PrintMyClass: X = 100, Y = 100, Dist = sqrt(x*x+y*y) = 141.42135623731
myClass.AnotherMyClass?.Dist:
myClass.AnotherMyClass?.Dist: 90
nameof(Console.Write) = Write
Bob is 20 years old.
Catch a message is "hi!" exception.
Press any key to EXIT...
C# 6.0 (VS2015 CTP6)的更多相关文章
- 使用Qt5.7.0 VS2015版本生成兼容XP的可执行程序 good(从VS2012 update1开始支持xp和c++11)
一.直接使用VS2012/VS2013/VS2015生成XP兼容的可执行程序 Visual Studio刚发布时没打补丁,称为RTM版,之后会陆续发布补丁,进行bug修复和功能增强.VS2010及之前 ...
- 使用Qt5.7.0 VS2015版本生成兼容XP的可执行程序
版权声明:本文为灿哥哥http://blog.csdn.net/caoshangpa原创文章,转载请标明出处. 一.直接使用VS2012/VS2013/VS2015生成XP兼容的可执行程序 Visua ...
- opencv3.2.0+opencv_contrib-3.2.0+vs2015开发配置
在sift算法实现中,出现了这个问题 出现问题:\vs2015opencv\vs2015\project\mode\mode\sift算法1.cpp(3): fatal error C1083: 无法 ...
- #一周五# VS2015 CTP6, TFS2015 CTP1更新,老衣的开发工具汇总,2015 MVP 社区巡讲
又到周五,这一周博主我工作效率极高,每天更新博客一篇,<快速创建网站>系列已经进程大半了,希望这个系列能够对大家有所帮助.今天周五了,博主要休息一下,就给大家唠叨一下这段时间都发生了什么. ...
- opencv3.0+VS2015+64位win7配置
首先,我们把所有用到的工具下载下来 VS2015 看这里,http://news.mydrivers.com/1/439/439398.htm,我下载的是专业版. OPENCV3.0 ...
- Windows8.1 + Nvidia cuda8.0 + Vs2015
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Vs2015 1.查看本机配置,查看显卡类型是否支持NVIDIA GPU选中计算机-->右键属性-->设备管理 ...
- WIN10-64+CUDA8.0+OpenCV3.0+VS2015配置
在网上参考了各位前辈的攻略后,捣鼓了两天总算配置成功了. 目前网上多的还是ubuntu上配置CUDA的教程比较多比较详尽,但是我现在就是想在windows10上跑啊,就是想用CUDA啊... 1.CU ...
- #一周五# VS2015 CTP6, TFS2015 CTP1更新,老衣的开发工具汇总,2015 MVP 社区巡讲
又到周五,这一周博主我工作效率极高,每天更新博客一篇,<快速创建网站>系列已经进程大半了,希望这个系列能够对大家有所帮助.今天周五了,博主要休息一下,就给大家唠叨一下这段时间都发生了什么. ...
- OpenCV3.2.0+VS2015开发环境配置
vs2015安装可参考:https://www.jianshu.com/p/391e67529bd3 OpenCV3.2.0配置可参考:https://www.jianshu.com/p/026093 ...
随机推荐
- 面试10大算法汇总+常见题目解答(Java)
原文地址:http://www.lilongdream.com/2014/04/10/94.html(为转载+整理) 以下从Java的角度总结了面试常见的算法和数据结构:字符串,链表,树,图,排序,递 ...
- Maven学习笔记—坐标和依赖
Maven的坐标和依赖 1 Maven坐标 1.1 什么是Maven坐标 Maven坐标:世界上任何一组构件都可以使用Maven坐标来唯一标识,Maven坐标的元素包括groupId.artifact ...
- Python基础-生成器和迭代器
生成器都是迭代器,迭代器不一定是生成器 def fansik(max): n, before, after = 0, 0, 1 while n < max: print(before) befo ...
- uwsgi+nginx项目上线
一.基础环境配置 1.Linux安装配置 1.设置IP地址 [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 ...
- pycharm一直scanning files to index
删除了c盘的垃圾文件之后,pycharm就一直scanning files to index 解决方法: 点击file,然后选择invalidate caches / restart ...,再弹出的 ...
- SourceTree的基本使用---基本介绍/本地开发
转载自https://www.cnblogs.com/tian-xie/p/6264104.html 1. SourceTree是什么 拥有可视化界面的项目版本控制软件,适用于git项目管理 wind ...
- iOS 学习如何声明私有变量和私有方法
私有变量 首先来说 OC 中没有绝对的私有变量,这么说基于两点原因: 1可修改: 通过KVC 键值编码 来修改私有成员变量的值 2可读取 : 通过底层runtime 获取实例变量Ivar 对应 ...
- C# 获取MD5值
class CommonHelper { /// <summary> /// 通过字符串获取MD5值,返回32位字符串. /// </summary> /// <para ...
- python 课堂笔记-if语句
# Author:zyl _username = 'zyl' _password = 'zyl123' username = input("username:") password ...
- GPU的工作原理
转:https://blog.csdn.net/p23onzq/article/details/79609629 在GPU出现以前,显卡和CPU的关系有点像“主仆”,简单地说这时的显卡就是画笔,根据各 ...