Description
In this article I will learn a new feature of C# 6.0 using Visual Studio Ultimate 2015 Preview.
Content
As all we know, Microsoft has launched a new version of C# called C# 6.0 with Visual Studio Ultimate 2015 Preview and there is new feature in C# 6.0 that is called "Initializers for auto-properties".
This feature allows us to initialize a property without using constructor in easy way. Let’s see this feature
I am using Visual Studio Ultimate 2015 Preview.

Open Visual Studio 2015 and select "File" -> "New" -> "Project..." and fill in the project name as "Console Application1".

After creating the project, I will create a class named "MyClass" with a property named "MyProp" only with a "get" and "set" in "program.cs".
Basically we set the property using a constructor like in the following code.
Code
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- public class MyClass
- {
- public int MyProp { get; set; }
- public MyClass
- {
- MyProp=10;
- }
- }
And we get the successful build in both, C# 5.0 and 6.0.
C# 5.0 in Visual Studio 2013
C# 6.0 in Visual Studio 2015 Preview
New Feature
In C# 6.0 we can also easily initialize the property with a successful build like in the following code:
- public class MyClass
- {
- public int MyProp { get; set; }=10;
- }

But when I write the same code in Visual Studio 2013 that works with C# 5.0, give me the unsuccessful build with an error.
If I initialize the property and print its value using an object of the class, it returns the value which is 10.
Conclusion
Now you understand the new feature of C# 6.0 that allows to use the "Initializers for auto-properties".

Robert GoodPosted Aug 3, 2015, 4:41 PM
A critical feature that VB had, but lacking in c#. Thanks for the great in-depth article. Verified working great in Windows 10, Visual Studio 2015 Enterprise. (public String TestInitialize { get; set; } = "";)
Saber ShaikhPosted Jan 1, 2015, 11:43 PM
good
Jitendra KumarPosted Jan 1, 2015, 10:58 AM
good..