#1,216 – C# 6.0 – Initializing Read-Only Auto-Properties from Constructors

In C# 6.0, when defining a read-only auto-property you can initialize the property as part of its declaration.

  public DateTime DogCreationTime { get; } = DateTime.Now;

You can also initialize these read-only auto-properties from a constructor.  For example:

    public class Dog
    {
        public string Name { get; }

        public Dog(string name)
        {
            Name = name;
        }
    }

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #1,216 – C# 6.0 – Initializing Read-Only Auto-Properties from Constructors

  1. Pingback: Dew Drop – October 31, 2014 (#1889) | Morning Dew

  2. Pingback: Parsing TypeScript definitions (functional-ly.. ish) | Dinesh Ram Kali.

Leave a comment