TechBubbles Microsoft Technology BLOG

C# 6.0 Features overview

This post outlines the new features that are added to the C# new version 6.0.

Enhancement to Auto Properties:  currently auto properties are needed to have setters. This puts disadvantage to immutable data types. Now C# 6 allows only getters on auto properties.C# 6 also   allows initializers to auto properties as shown in the following picture




Using Static classes – Now you can put static members directly into the scope without using their class names





 String interpolation – Existing string.format function




With the new syntax you can define the escape characters inside { } .





Expression-bodied methods – You can use lambda arrow to just implement the single expression. Often it looks like this





But now you re-write the above in single line



Index initializers – today you can initialize properties in object initializers








But indexers still have to assign in separate statements. Now you can initialize indexes inside object initializers as shown below




Null Conditional Operators – today we do null condition checking for indexers as below






In C# 6 , there is no explicit null check by using ? . Operator. The new way of writing above follows





It works like, if left hand side is null, the whole thing is null. Only when it is not null it does the dot(.)    then it becomes as result of the operation. Delegate null checking can be written as follows





Exception Filters: There are few improvements to Catching, finally. Visual basic and F# both allow catch block to filter exceptions before actually catching them and now C# allows that too, this is better than catching and re-throwing , when you re-throw the exception you lose the information about where the originally occurred.








Await in catch and finally blocks –  



with the introduction of these enhanced features in C# 6.0, developers can certainly write some cleaner code with less lines code using C# 6.0

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me


Tag Cloud