This project is read-only.

Primary Constructors

Topics: C# Language Design
Dec 29, 2015 at 7:55 PM
C# 6.0 didn't ship having the proposed primary constructors--I imagine because of difficulty getting all the language and compiler services to deal with the super-awkward proposed syntax.

I like the idea of a constructor the must be called, but why not handle it just by making the compiler understand a one-word enhancement to a normal constructor:
class Person {
  public Name { get; }
  primary public Person( string name ) {
    this.Name = name;
Of course the compiler would treat the word primary as special only here, and compilation should die with an error if more than one constructor is marked as primary, or if another constructor is ever added which fails to call the primary constructor.
Dec 29, 2015 at 11:02 PM
These discussions have moved to