October 17, 2014 by Anuraj
.Net ASP.Net Visual Studio
Today I got a chance to look into C# 6.0 features. Thanks to ORTIA(Technology innovation division of Orion India Systems), for providing me the MSDN subscription. :)
- Exception filters : Exception filters lets you specify a condition for a catch block. The catch block gets executed only if the condition is satisfied.
The above code will write 10, as the Error code property is set to 10.
- Declaration expressions - This feature simply allows you to declare local variable in the middle of an expression.
The above code snippet can be re-written as like the following in C# 6.0
- using static - This feature allows you to specify a particular type in a using statement after that all static members of that type will be accessible is subsequent code.
- Auto property initializer - With C# 6 initialize auto properties just like a field at declaration place.
- Primary Constructor - This feature helps to capture parameters of primary constructor to fields, in the class for furthur processing. When declaring a primary constructor all other constructors must call the primary constructor using :this().
- Dictionary Initializer - C# made the Dictionary more cleaner.
Can be re-written like this
Note : These are experimental features, you have to explicitly enable this, otherwise VS2014 will show an error, while compiling like this. - Feature ‘primary constructor’ is only available in ‘experimental’ language version.
You can do this manually editing the project file.(I didn’t found any option to do this via Visual Studio.) You can open the *.csproj file in your favorite text editor and add the following line.
Now it will be like this
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub