C# 6.0 lets the developers to initialize the read only properties directly when declaring them .
Since it is a read-only property , it behaves the same as read only variable where you can initialize the read-only auto properties from a constructor.
Initialize Read-only Properties from Constructor in C# 6.0
Below is a sample code snippet demonstrating how to initialize read-only properties from constructor in C# 6.0
public class Employee { public string ACName { get; set; } public DateTime CreatedDate { get; } public Employee() { CreatedDate = DateTime.Now; } }
Leave a Reply