C# 6.0 新機能download.microsoft.com/download/F/F/F/FFF40A16-BFC2-4814...VB8 / C#2.0.NET2.0 VS2005...
Transcript of C# 6.0 新機能download.microsoft.com/download/F/F/F/FFF40A16-BFC2-4814...VB8 / C#2.0.NET2.0 VS2005...
ROOM
G
•
•
1.
2.
•
VB7 / C#1.0
.NET1.0
VS2002
VB8 / C#2.0
.NET2.0
VS2005
VB9 / C#3.0
.NET3.5
VS2008
VB11 / C#5.0
.NET4.5
VS2012
言語
フレームワーク
ツール
三位一体の進化
電球マーク(修正、リファクタリング)
強化方針:
1. たくさんの小さな新機能
2. コード量削減
C#6.0
Using static
using System.Math;
public class Point
{
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
}
Using static
using System.Math;
public class Point
{
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
}
Using static
using static System.Math;
public class Point
{
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
}
public Point Add(Point point)
{
if (point == null)
{
throw new ArgumentNullException("point");
}
}
Nameof 演算子
public Point Add(Point other)
{
if (other == null)
{
throw new ArgumentNullException("point");
}
}
Nameof 演算子
public Point Add(Point point)
{
if (point == null)
{
throw new ArgumentNullException(nameof(point));
}
}
Nameof 演算子
public Point Add(Point other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
}
Nameof 演算子
Null 条件演算子public static Point FromJson(JObject json)
{
if (json != null &&
json["x"] != null &&
json["x"].Type == JTokenType.Integer &&
json["y"] != null &&
json["y"].Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
Null 条件演算子public static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
Null 条件演算子public static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
?.
Null 条件演算子public static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
Null 条件演算子public static Point FromJson(JObject json)
{
if (json?["x"]?.Type == JTokenType.Integer &&
json?["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
Null 条件演算子
OnChanged(this, args);
Null 条件演算子
if (OnChanged != null)
{
OnChanged(this, args);
}
Null 条件演算子
{
var onChanged = OnChanged;
if (onChanged != null)
{
onChanged(this, args);
}
}
Null 条件演算子
OnChanged?.Invoke(this, args);
自動プロパティの機能強化public class Point
{
public int X { get; } = 5;
public int Y { get; } = 7;
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
・・・
}
インデックス初期化子public class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
var result = new JObject();
result["x"] = X;
result["y"] = Y;
return result;
}
}
インデックス初期化子public class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
var result = new JObject() { ["x"] = X, ["y"] = Y };
return result;
}
}
インデックス初期化子public class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
return new JObject() { ["x"] = X, ["y"] = Y };
}
}
インデックス初期化子public class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson() =>
new JObject() { ["x"] = X, ["y"] = Y };
}
• C# の歴史
• C#6.0 新機能
1.コーディングエクスペリエンス
2.言語の強化
Language features in C#6 and VB 14http://roslyn.codeplex.com/
C# Frequently Asked Questionshttp://blogs.msdn.com/b/csharpfaq/
The Visual Studio Team Blog
http://blogs.msdn.com/b/visualstudio/
リソース
アンケートにご協力ください。
●アンケートに上記のSession ID のブレイクアウトセッションに
チェックを入れて下さい。
●アンケートはお帰りの際に、受付でご提出ください。
マイクロソフトスペシャルグッズと引換えさせていただきます。
Ask the Speaker のご案内
●本セッションの詳細は、EXPO 会場内
『Ask the Speaker』コーナー
Room G カウンタにてご説明させて
いただきます。是非、お立ち寄りください。
Ask the Speaker
EXPO会場MAP