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

No Responses

Leave a Reply