从 C# 8 开始,我们可以做类似的事情:
public class MyClass(int a) { // note, this is NOT the constructor, but the class declaration }
这是如何运作的?
对于C#7,它被标记为实验性功能;但我找不到有关它的文档。 C# 8 仍被视为实验性的吗?
我看到这个:
此功能是一个主构造函数,在 C# 12 上发布 https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors#primary-constructors