Auto Property Initializer in C# 6.0

In our previous article, we have discussed the new features introduced in C# 6.0. You can go through that here.

In this article, you will learn:

  • Auto Property Initializer in C#
  • What is Auto Property Initializer in C#?
  • How it works?

What is Auto Property Initializer in C# ?

This feature enable you to set the values of properties where they are declared.
Previously, we use constructor to initialize the auto properties to non-default value but with this new feature in C# 6.0, it doesn’t require to initialize these properties with a constructor as shown below: 

Auto-implemented property are being enhanced in two ways: they can be initialized inline, and you can define them without a setter. With inline initialization we can provide an initial value for the auto-implemented property without having to manually set the property via a constructor.

© 2015, www.techkatak.com. All rights reserved.