What's New in C# 6、New Language Features in C# 6 をベースに、C# 5 と比較してコードがどう変わるのかを、主な機能に絞って記載しています。
1. 自動プロパティの機能強化 (Auto-Property enhancements)
自動プロパティの初期化子 (Auto-Property initializers)
old
public class Customer {
public Customer() {
First = "Jane";
Last = "Doe";
}
public string First { get; set; }
public string Last { get; set; }
}

public Customer(string name) {
_name = name;
}
public string Name { get { return _name; } }
}
<div>:arrow_down:</div>
```csharp:new!
public class Customer {
public Customer(string name) {
Name = name;
}
public string Name { get; }
}
2. 式形式のメンバー (Expression-bodied function members)
式形式のメソッド (Expression bodies on method-like members)
old
public void Print() {
Console.WriteLine(First + " " + Last);
}


3. using static
old
using System;
class Program {
static void Main() {
Console.WriteLine(Math.Sqrt(3*3 + 4*4));
Console.WriteLine(DayOfWeek.Friday - DayOfWeek.Monday);
}
}

class Program {
static void Main() {
WriteLine(Sqrt(33 + 44));
WriteLine(Friday - Monday);
}
}
## 4. [Null 条件演算子 (Null-conditional operators)](https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/operators/null-conditional-operators)
```csharp:old
var handler = PropertyChanged;
if (handler != null) {
handler(this, args);
}

5. 文字列補間 (String interpolation)
old
var s = String.Format("{0,20} is {1:D3} year{2} old", p.Name, p.Age, (p.Age == 1 ? "" : "s"));

6. nameof
式 (nameof
Expressions)
old
if (x == null) throw new ArgumentNullException("x");

7. インデックス初期化子 (Index initializers)
old
var numbers = new Dictionary<int, string> {
{7, "seven"},
{9, "nine"},
{13, "thirteen"},
};

8. 例外フィルター (Exception filters)
old
try { … }
catch (MyException e) {
if (myfilter(e)) {
…
}
}

9. catch / finally ブロックでの await (Await in catch and finally blocks)
old
Resource res = null;
try {
res = await Resource.OpenAsync(…);
…
}
catch(ResourceException e) {
Resource.LogAsync(res, e).Wait();
}
finally {
if (res != null) {
res.CloseAsync().Wait();
}
}
