In previous post I showed you the benefit of "nameof" expression and today in this post I will show you how to initialize/set default values to auto properties introduced in C# 6.0. Also I hope you all have downloaded the new Visual Studio 2015 Preview version and .NET 4.6
After Microsoft introduced Auto-properties, developers were asking to initialize or set default values to auto properties where it has been declared. Prior to C# 6.0, if we need to have some default value to the Property than we need to create them as a Full Property with a private variable to initialize at the time of declaration. But with new C# 6.0, you don't have to create the Full Property in order to initialize them
Typical Auto-Property looks similar to the below code :
But now with new C# 6.0 developer can assign the default values without creating a private variable. Just place an "=" equal sign at the end and assign the default value to it. Below is the example.
Now whenever user creates the instance of the class, it will automatically set the default value to the properties and when you call the properties you will see the default values if its not re-initialized.
Its really a small feature but it does increases the productivity. Hope you like the feature. Please do comment if you want to share the opinion. Happy Coding.