C# 6


All C# 6 features with short examples

It’s time to sum up all C# 6 features. Here is a list of all goodness with short examples implemented and tested in Visual Studio 2015. nameof String interpolation Null-conditional (?. and ?[]) and null-coalescing (??) operators Index initializers Extension methods visible in collection initializers Exception filters Auto-property initializers Expression-bodied members Static using Extended async / await support I’ve also found few features that were planned to be included in C# 6 but finally where dropped. Parameterless constructors in structs – details in New Features in C# 6 article from November 2014 Primary constructions – details in The New and […]


C# 6 features – Static using

One more C# 6 syntactic sugar feature is static using.  The feature eliminate explicit reference to the type when invoking a static method.


C# 6 features – Auto-property initializers

Properties were always a more powerful version of fields. But sometimes you just want them to behave the same and the concise notation was not available. It’s fixed in C# 6.


C# 6 features – Exception filters

Exception filters were already available in Visual Basic and F#, but not in C#. Recent release of C# 6 makes it equal. Below is example of exception filters syntax in C# 6. try { // do something dangerous } catch (Exception e) when (MyFilter(e)) { // action } If the expression after when  evaluates to true, the catch block is run, otherwise the exception keeps going. Next example: try { // … throw new ArgumentNullException(paramName: “someParam”); } catch (ArgumentNullException e) when (e.ParamName == “differentParam”) { // Appropriate action } In the above, the exception type matches and condition that follows […]


C# 6 features – String interpolation

This article is part of series about C# 6 features. Let focus on string interpolation this time. It’s one of the new C# features that will for sure affect the way you write C# code.