Initializers for Read-Only Auto Properties in C# 6.0

C# 6.0 Features Series

In C# 6.0 , we can use the initializers for the auto properties to initialize the value for the read only auto properties .

How to Initialize a Read-Only Auto Properties in C# 6.0 ?

Here’s a code snippet that demonstrates how to initialize a read-only auto property in C# 6.0.

public class Employee
{
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime ModifiedDate { get;  } = DateTime.Now;
}

One thought on “Initializers for Read-Only Auto Properties in C# 6.0

  1. Pingback: Lambda and Getter Only Auto-Properties in C# 6.0 | Developer Publish

Leave a Reply

Your email address will not be published. Required fields are marked *