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()
 {
   Name=m_Name;
 }

}

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;
}
Advertisements

One thought on “New Features in C# 6.0 – Auto-Property Initializers

  1. new homes

    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.

    Reply

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s