Parameterless constructor is not a must-provided by user when a struct has a field initializer

已关闭 适合新手
#56,424 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp
领域
documentation

调研方向

打开 docs/csharp/programming-guide/classes-and-structs/using-constructors.md,找到“字段初始值设定项需要无参数 struct 构造函数”这一说法。请澄清:声明带参数的构造函数时,编译器会生成一个无参数构造函数,并使表述与提供的示例一致;当措辞准确描述这一行为时,即为完成。

由索引模型根据 Issue 内容生成。

描述

:watch: Not Triaged dotnet-csharp/svc fundamentals/subsvc
Type of issue

Typo

Description

Dear,

The original description If you declare any field initializers in a struct type, you must supply a parameterless constructor. is not very precise because the following code compiles and runs:


var ss = new SS();
Console.WriteLine(ss.x); // output 0

var sss = new SS(1);
Console.WriteLine(sss.x); // output 1


public struct SS
{
    public int x = 1;
    public SS(int z)
    {
    }
}

The compiler will generates a parameterless constructor when a non-parameterless constructor is provided.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-constructors

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/programming-guide/classes-and-structs/using-constructors.md

Document Version Independent Id

36d0bf3a-29bf-5162-c700-142b03f9a16c

Platform Id

42802e43-5862-c431-46d9-821596208b94

Article author

@BillWagner

Metadata
  • ID: 374a58d4-1905-c664-04b6-fd68e617f8c9
  • PlatformId: 42802e43-5862-c431-46d9-821596208b94
  • Service: dotnet-csharp
  • Sub-service: fundamentals

Related Issues

主要语言
没有语言数据
星标
4.8k
派生
6.1k
平均合并
1 天 5 小时
30 天内合并 PR
213

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/docs 的其他 Issue

查看 dotnet/docs 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。