Recently there has been a lot of posts about some of the new features in C# 6.0 due to VS 2015 Preview etc. however some of these feature were mentioned early 2014 around April and May.

In a little series I’ll make some very short posts simply showing off the features in C# 6.0 and the differences. So without further ado I present to you:

C# 6.0 – Auto implemented property initializers

In C# 6.0 you’re now able to initialize an auto implemented property as follows

public class Person 
{ 
    public string Name { get; set; } = "Woody Buzz"; 
}

whereas you before might had to initialize it through the constructor such as

public class Person 
{ 
    public Person(string name) 
    { 
        Name = name; 
    } 
    public string Name { get; set; }; 
}

Getter-only property

C# 6.0 also enables the possibility of omitting the setter in auto implemented properties such as

public class Person
{
    public string Name { get; } = "Woody Buzz"; 
}

and this will implicitly create the backing field as readonly. This eases the use of structs in the aspect of now having immutability when using auto implemented properties. You can of course also initialize it through the constructor as usual.

That’s it for now!