What’s New in C#6
Jason Bock
Practice Lead
»http://www.magenic.com
»http://www.jasonbock.net
»https://www.twitter.com/jasonbock
»https://www.github.com/jasonbock
»jasonb@magenic.com
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
Language Evolution
13 years in the making…
»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 andYield
»Static and Partial Classes
»NullableTypes
Language Evolution
Version 2
»LINQ
› Object and Collection Initializers
› AnonymousTypes
› ExpressionTrees
› Extension Methods
Language Evolution
Version 3
»Co- and Contravariance
»Dynamic
»Named and Optional Arguments
Language Evolution
Version 4
»Async/Await
Language Evolution
Version 5
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
Language Evolution
https://github.com/dotnet/roslyn
»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 forArgumentNullException, 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://dialectline.files.wordpress.com/2012/04/crystal_ball1.jpg
Future Directions
https://github.com/dotnet/roslyn/issues?q=is%3Aopen+is%3Aissue+label%3A%22Up+for+Grabs%22
Future Directions
https://github.com/dotnet/roslyn/issues/98
»My choices/ideas
› Generic attributes: [MyMetadata<string>]
› Fault blocks: try { … } fault { … }
› Metaprogramming: [Disposable] public class MyClass
› Reactive programming
Future Directions
What’s New in C#6
Jason Bock
Practice Lead
Remember…
 https://github.com/JasonBock/WhatsNewInCSharp6
 http://www.slideshare.net/jasonbock/whats-new-in-c6
 References in the notes on this slide

What's New in C#6

Editor's Notes

  • #6 It’s hard to believe that C# has 13 years of history. Its official release was in 2002, and along the way it’s picked up a fair amount of features.
  • #7 Version 1 had some “standard” language features that one would arguably expect from an OOP language.
  • #8 Version 2’s biggest addition was generics. That alone made coding easier to write, especially when it came to collections.
  • #9 LINQ was the biggest addition for C#3. With it came a whole slew of features to support it.
  • #10 Verison 4 added some “interesting” features, with dynamic opening the door to C# being a little less type-safe.
  • #11 Version 5’s biggest (and maybe only) feature is async/await, making asynchronous/concurrent programming easier.
  • #12 But all of C#’s evolution up to version 5 has felt like it’s been done in a dark, brooding tower. It’s not been an open process. Sure, MS has listened to customers, but to directly influence the processes has been difficult at best.
  • #13 But now, in 2015, the .NET world is rapidly changing. The direction of .NET is OSS. The framework itself is being pushed to GitHub in bigger and bigger chunks all the time. .NET Core is targeting OSes other than MS. It’s a strange new world, but it’s opening up a lot of collaboration for developers.
  • #14 The language space is completely open now as well. You can download the source code to the compilers and hack away (and submit pull requests if you’d like). You can watch as the language teams discuss current and potentially future changes. This is completely unlike the .NET of 2002.
  • #15 With Version 6, there’s a lot of features to cover. And it’s interesting to note that a fair amount of these (like string interpolation) went through a lot of changes before it reached its final destination. Some features, like primary constructors, have been dropped for now (though they may come back in a future version). All this work was driven a lot by the community and what really worked best.
  • #21 So, where will C# go from here? As with any crystal ball gazing, sometimes the best we can do is guess.
  • #22 One thing you can do is get involved with current language/compiler issues. There’s always a backlog of “Up for Grabs” issues.
  • #23 You can also watch the Design Notes discussions and start contributing ideas for future versions of C#. My personal vote is for more metaprogramming support, YMMV 
  • #24 What would I like? * Generic attributes (supported in the CLR already, would be "easy" to bring in, similar situation for co/contravariance) * Fault blocks (supported in the CLR, should be "easy" to bring in) * Metaprogramming (macros? attribute-dependent?) * Reactive programming as a first-class concept (events, make them observables, maybe even generators, ala ES6 and 7 - https://www.youtube.com/watch?v=DqMFX91ToLw)