New Features in C# 6.0 – Auto-Property Initializers

Initialize property is repetitive task, and cannot be done in the same line as we can can done for fields. For example we can write:

public class Person
 private string m_Name="Default Name";
 public string Name {get;set;}
 public Person()


As we can see Property can be initialized only in the constructor, beside the filed which can be initialized in the same line where it is declared. The new feature in C# 6.0 defines Auto-Property initializer alowing property to be initialized like fields. The following code snippet shows the Auto-Property Initializer;

public class Person
 static string m_Name="Default Name";
 static string Name {get;set;}=m_Name;

About Bahrudin Hrnjica

PhD in Mechanical Engineering, Microsoft MVP for Visual Studio and Development Technologies. Likes .NET, Math,Data Science, Evolutionary Algorithms, Machine Learning, Blogging.

Posted on 10/10/2014, in .NET, C#, CodeProject and tagged , , , . Bookmark the permalink. 1 Comment.

  1. Live Interior 3D is flexible, allowint that you creaate 3D models,
    and detailed 2D floor plans as well. Vendor coupons are offered also on thee website, but
    you’ll receive a pack of coupons using your admission ticket.
    The ssimple facts are Tiffany had created an ‘all eyes on me’ Donna Faye Couture design foor my red carppet look.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s