Parameterless constructors in structs for C# 6

后端 未结 2 1078
孤街浪徒
孤街浪徒 2020-12-10 01:02

My understanding is that Parameterless constructors in structs are now allowed.

But the following gives me a compile error in VS 2015 Community

publi         


        
2条回答
  •  囚心锁ツ
    2020-12-10 01:12

    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:

    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.

提交回复
热议问题