My understanding is that Parameterless constructors in structs are now allowed.
But the following gives me a compile error in VS 2015 Community
public struct Person
{
public string Name { get; }
public int Age { get; }
public Person(string name, int age) { Name = name; Age = age; }
public Person() : this("Jane Doe", 37) { }
}
Error: "Structs cannot contain explicit parameterless constructors"
Anyone know why?
The feature was present in older previews of C# 6.0, which is why some articles talk about it. But it was then removed and so it's not present in the version distributed with VS 2015 RC.
Specifically, the change was reverted in pull request #1106, with more information about the rationale in issue #1029. Quoting Vladimir Sadov:
The feature was then added back in C# 10.0.