C# 6 结构中的无参数构造函数

Parameterless constructors in structs for C# 6

我的理解是现在允许结构中的无参数构造函数。

但是下面在 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) { } 
}

错误:"Structs cannot contain explicit parameterless constructors"

有人知道为什么吗?

该功能在 C# 6.0 的旧预览版中存在,这就是为什么有些文章会谈论它的原因。但它随后被删除,因此它不存在于 VS 2015 RC 分发的版本中。

具体来说,更改已在 pull request #1106, with more information about the rationale in issue #1029 中恢复。引用弗拉基米尔·萨多夫 (Vladimir Sadov) 的话:

As we performed more and more testing, we kept discovering cases where parameterless struct constructors caused inconsistent behavior in libraries or even in some versions of CLR.

[…]

After reconsidering the potential issues arising from breaking long standing assumptions, we decided it was best for our users to restore the requirement on struct constructors to always have formal parameters.

The feature was then added back in C# 10.0.