Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

C#6.0の新機能紹介

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio

Eche un vistazo a continuación

1 de 32 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a C#6.0の新機能紹介 (20)

Anuncio

Más de Kazunori Hamamoto (19)

Más reciente (20)

Anuncio

C#6.0の新機能紹介

  1. 1. C# 6.0のご紹介 Japan Windows Azure User Group 福岡支部 濱本一慶(@airish9)
  2. 2. 自己紹介 2 濱本一慶(はまもとかずのり) @airish9 C#とVB.NETでご飯を食べてます! エンタープライズ系の開発中心 Azureで好きなサービスはモバイルサービス お仕事ではC#とVB.NETを半々くらい
  3. 3. アジェンダ 3 C#の今まで C#のこれから C# 6.0の新機能 C# 6.0の体験方法
  4. 4. C#の今まで 4 ジェネリクス C#1.0 2000年 C#2.0 2004年 C#3.0 2007年 C#4.0 2008年 C#5.0 2012年 C#6.0 20XX年 クラス ラムダ式 LINQ dynamic await/async Roslyn
  5. 5. 注目度は… 5 Google先生が言うにはJavaが断トツ人気・・・。
  6. 6. C#のこれから 6 2014年4月 C#にとって大きな出来事が…
  7. 7. C#のこれから 7 Roslynがオープンソースになりました!! http://roslyn.codeplex.com/
  8. 8. Roslynって何? 8 .NET Frameworkの次世代コンパイラプラットフォーム Compiler APIs • コンパイラ Feature APIs • Code Fixやリファクタリング等 Workspace APIs • プロジェクトファイルや参照関係
  9. 9. C# 6.0 9 Visual Studio 14で使用可能(現在はCTP3) 実はVisulaBasicも便利になります Roslyn ≒ C#6.0
  10. 10. C#6.0の実装状況 10 要点例進捗どうですか Primary constructors class Point(int x, int y) { … } Done Auto-property initializers public int X { get; set; } = x; Done Getter-only auto-properties public int Y { get; } = y; Done Using static members using System.Console; … Write(4); Done Dictionary initializer new JObject { ["x"] = 3, ["y"] = 7 } Done Indexed member initializer new JObject { $x = 3, $y = 7 } Withdrawn Indexed member access c.$name = c.$first + " " + c.$last; Withdrawn Declaration expressions int.TryParse(s, out var x); Done Await in catch/finally try … catch { await … } finally { await … } Done Exception filters catch(E e) if (e.Count > 5) { … } Done http://roslyn.codeplex.com/wikipage?title=Languag e%20feature%20status&referringTitle=Home Exists できてた Done できた Planned やってます Maybe 多分する Withdrawn やりたい No 今は無理 N/A 必要なし
  11. 11. C#6.0の実装状況 11 要点例進捗どうですか Typecase Select Case o : Case s As String : … No Guarded cases Select Case i : Case Is > 0 When i Mod 2 = 0 No Partial modules Partial Module M1 N/A Partial interfaces Partial Interface I1 Exists Multiline string literals "Hello<newline>World" Exists Year-first date literals Dim d = #2014-04-03# N/A Binary literals 0b00000100 Planned Digit separators 0xEF_FF_00_A0 Planned Line continuation comments Dim addrs = From c in Customers ' comment N/A TypeOf IsNot If TypeOf x IsNot Customer Then … N/A Expression-bodied members public double Dist => Sqrt(X * X + Y * Y); Planned Event initializers new Customer { Notify += MyHandler }; Planned Null propagation customer?.Orders?[5]?.$price Done Semicolon operator (var x = Foo(); Write(x); x * x) Maybe Private protected private protected string GetId() { … } Withdrawn Params IEnumerable int Avg(params IEnumerable<int> numbers) { … } Planned Constructor Inference new Tuple(3, "three", true); Maybe String interpolation "{p.First} {p.Last} is {p.Age} years old." Maybe TryCast for nullable Dim x = TryCast(u, Integer?) Exists Delegate combination with + d1 += d2 Exists
  12. 12. C#6.0の実装状況 12 要点例進捗どうですか Implicit implementation Class C : Implicitly Implements I Exists nameof operator string s = nameof(Console.Write); Exists Strict modules Strict Module M Exists Faster CInt Dim x = CInt(Math.Truncate(d)) | Exists #pragma #Disable Warning BC40008 Exists Checked and Unchecked blocks Checked : x += 1 : End Checked Exists Field targets on autoprops <Field: Serializable> Property p As Integer Planned If(b,e1,e2) uses type context Dim x As Integer? = If(b,1,Nothing) N/A
  13. 13. C#6.0の実装状況 13 要点例 Primary constructors class Point(int x, int y) { … } Auto-property initializers public int X { get; set; } = x; Getter-only auto-properties public int Y { get; } = y; Using static members using System.Console; … Write(4); Dictionary initializer new JObject { ["x"] = 3, ["y"] = 7 } Declaration expressions int.TryParse(s, out var x); Await in catch/finally try … catch { await … } finally { await … } Exception filters catch(E e) if (e.Count > 5) { … } Partial interfaces Partial Interface I1 Multiline string literals "Hello<newline>World" Null propagation customer?.Orders?[5]?.$price TryCast for nullable Dim x = TryCast(u, Integer?) Delegate combination with + d1 += d2 Implicit implementation Class C : Implicitly Implements I nameof operator string s = nameof(Console.Write); Strict modules Strict Module M Faster CInt Dim x = CInt(Math.Truncate(d)) | #pragma #Disable Warning BC40008 Checked and Unchecked blocks Checked : x += 1 : End Checked 19機能が実装済
  14. 14. Auto-property initializers 14 自動実装プロパティの初期化がコンストラクタで可能になりました! Before class Person { public int Age { get;set; } public Person() { Age = 20; } } Next class Person { public int Age { get;set; } = 20; }
  15. 15. Getter-only auto-properties 15 Getterのみの自動実装プロパティの初期化もできます Before class Person { public int Age { get { return this._age; } } private int _age = 20; } Next class Person { public int Age { get; } = 20; }
  16. 16. Primary constructors 16 クラス定義と同時にコンストラクタを宣言する Before class Person { public string Name { get;set; } public Person(string name) { this.Name = name; } } Next class Person(string name) { public string Name { get;set; } = name; }
  17. 17. Primary constructors 17 コンストラクタと同じように処理も記述できます Before class Person { public string Name { get; set; } public Person(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("name is NullOrEmpty"); this.Name = name; } }
  18. 18. Primary constructors 18 コンストラクタと同じように処理も記述できます After class PersonNext(string name) { { if (string.IsNullOrEmpty(name)) throw new ArgumentException("name is NullOrEmpty"); } public string Name { get;set; } = name; }
  19. 19. Using static members 19 静的クラスの静的メソッドは省略可能になります Before class Person { public void Say() { System.Console.WriteLine("Name is " + this.Name); } } After using System.Console; class Person { public void Say() { Console.WriteLine("Name is " + this.Name); } }
  20. 20. Declaration expressions 20 Parseする時に無駄な変数を宣言しなくてよくなります。 Before public void Say() { int number; if (int.TryParse("20", out number)) { System.Console.WriteLine(number + "歳です"); } } After public void Say() { if (int.TryParse("20", out var number)) { Console.WriteLine(number + "歳です"); } Console.WriteLine(number + “歳です”); //スコープ外なのでエラー }
  21. 21. Await in catch/finally 21 Catch句とFinally句でawaitが使用できようになりました After try { //HodeHoge } catch (Exception e) { await Task.Delay(2000); } Before Exception exception = null; try { //HodeHoge } catch (Exception e) { exception = e; } if (exception != null) await Task.Delay(2000);
  22. 22. Exception filters 22 Catch句に条件式を付与する事ができるようになりました After try { //HogeHoge } catch (Exception e) if (e.Data.Count > 10) { //例外処理 } Before try { //HogeHoge } catch (Exception e) { if (e.Data.Count > 10) { //例外処理 } }
  23. 23. Null propagation 23 nullチェックをシンプルに記述できます Before public int? GetNameLength(Person person) { if (person == null) return null; if (person.Name == null) return null; return person.Name.Length; } After public int? GetNameLength(Person person) { return person?.Name?.Length; }
  24. 24. nameof operator 24 メンバや変数の名前を返す演算子 Before class Person { public string Name { get; set; } public Person(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("name" + " is NullOrEmpty"); this.Name = name; } } 文字列指定
  25. 25. nameof operator 25 メンバや変数の名前を返す演算子 After public string Name { get; set; } public Person(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentException(nameof(name) + "is NullOrEmpty"); this.Name = name; } nameof演算子で タイプセーフ
  26. 26. 参考元 26 Roslynについて情報が整理されているサイト ++C++; // 未確認飛行C ブログ  http://ufcpp.wordpress.com xin9le.net  http://xin9le.net/
  27. 27. Roslyn(C#6.0)を使うには 27 1. Visual Studio 14 CTPをインストール http://www.visualstudio.com/en-us/downloads/visual-studio- 14-ctp-vs 2. プロジェクトファイルを編集 次ページにて詳細を説明 しかし、2014年9月時点ではVisualStudio 14 CTPは side-by-sideできない・・・
  28. 28. Roslyn(C#6.0)を使うには 28 プロジェクトファイルの編集箇所 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin¥Debug¥</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <LangVersion>experimental</LangVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin¥Release¥</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <LangVersion>experimental</LangVersion> </PropertyGroup> 追加 追加
  29. 29. もっと簡単にRoslynを体験するには… 29
  30. 30. もっと簡単にRoslynを体験するには… 30 Azureの仮想マシンを作成 ギャラリーからVisualStudio 14 CTPを選択
  31. 31. お知らせ 31  C#erが集まって、ゆるーくhogehogeやってます  C#に限らずMicrosoft系の開発の集まりです  「C#勉強会福岡」を不定期で開催中  興味がある方はFacebookページからどうぞ
  32. 32. ご清聴ありがとうございました! 32

×