what's new in c#6
TRANSCRIPT
»http://www.magenic.com
»http://www.jasonbock.net
»https://www.twitter.com/jasonbock
»https://www.github.com/jasonbock
Personal Info
https://github.com/JasonBock/
WhatsNewInCSharp6
http://www.slideshare.net/jasonbock/whats-new-in-c6
Downloads
»Language Evolution
»C#6 Features
»Future Directions
Overview
Remember…https://github.com/JasonBock/
WhatsNewInCSharp6
http://www.slideshare.net/jasonbock/whats-new-in-c6
»Classes (and Interfaces) and Structs
»Common Control Flow (switch, if/else, etc.)
»Exception Handling (try/catch/finally)
»Visibility (public/protected/private)
»Delegates and Events
Language Evolution
Version 1
»Generics
» Iterators and Yield
»Static and Partial Classes
»Nullable Types
Language Evolution
Version 2
»LINQ› Object and Collection Initializers
› Anonymous Types
› Expression Trees
› Extension Methods
Language Evolution
Version 3
Language Evolution
http://static.hdw.eweb4.com/media/wallpapers_1920x1080/fantasy/1/1/dark-tower-fantasy-hd-wallpaper-
1920x1080-5771.jpg
Language Evolution
http://www.dotnetfoundation.org/
The .NET Foundation is an independent organization to foster open development and collaboration around the growing collection of open source technologies for .NET
»Auto-property initializers
»Getter-only auto-properties
»Ctor assignment to getter-only autoprops
»Using static members
»Dictionary initializer
»Await in catch/finally
»Exception filters
Language Evolution
Version 6
https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14
»Expression-bodied members
»Null propagation
»String interpolation
»nameof operator
»#pragma
»Extension Add in collection initializers
» Improved overload resolution
»Auto-property initializers› TODO: Finish
»Getter-only auto-properties› TODO: Finish
»Ctor assignment to getter-only autoprops› TODO: Finish
C#6 Features - Properties
»Using static members› Static members always require the name of the class for resolution
› using “using static” removes that
› E.g. - using static System.Math;
› This also “imports” all the extension methods as well
»Expression-bodied members› If a method is short – e.g. one line of code – you can now define without the curly
braces
› E.g. public int Double(int x) => Add(x, x);
C#6 Features - Functions
»Null conditional› Enables safe access to members in deep object graphs
› E.g. - parent.Child?.ToString()
»String interpolation› Allows you to define the “holes” directly in a formattable string
› E.g. - $"{this.FirstName} {this.LastName}"
»nameof› Provides a way to get the name of a member in code
› Removes the need for magic string usage
› Useful for ArgumentNullException, property changed implementations, WeakEventManager, etc.
C#6 Features – Syntax
»Await in catch/finally› Before C#6, you couldn’t await a method in a catch or finally block. Now you can!
› E.g. – try { /* ... */ } catch(MyException) { await SomeCall(); }
»Exception filters› VB has always had the ability to filter exceptions – that is, only enter a catch block if
some condition is true. Now C#6 has it!
› E.g. – catch(MyException) when (this.HandleIt) { /* ... */ }
C#6 Features - Exceptions
»Dictionary initializer› Is really an “index” initializer. Can be used for dictionaries or any object with an
indexer
› E.g. – var things = new Things { [0] = "Tesla" };
»#pragma› Now works with an identifier as well as an integer, which maps to C# errors
› E.g. these are the same− #pragma warning disable 219
− #pragma warning disable CS0219
› Potentially useful for analyzer errors to disable/enable rather than using SuppressMessageAttribute everywhere
C#6 Features - Miscellaneous
Future Directions
https://github.com/dotnet/roslyn/issues?q=is%3Aopen+is%3Aissue+label%3A%22Up+for+Grabs%22
»My choices/ideas› Generic attributes: [MyMetadata<string>]
› Fault blocks: try { … } fault { … }
› Metaprogramming: [Disposable] public class MyClass
› Reactive programming
Future Directions