Skip to content

Positional parameters in records can create fields instead of properties #44041

@BillWagner

Description

@BillWagner

Type of issue

Missing information

Description

These declarations are both legal:

public record class C(int X)
{
    public int X = X; // effectively this.X = X
}

public record struct S(int X)
{
    public int X = X; // effectively this.X = X
}

This article only talks about "properties", which is the default for a record's primary constructor parameter. It should include how to create a public field as well.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/builtin-types/record.md

Document Version Independent Id

de1f383b-ef20-4776-57a8-04edae892166

Article author

@BillWagner

Metadata

  • ID: 20818c64-4ad8-fb15-5d79-e7f98614e9c4
  • Service: dotnet-csharp
  • Sub-service: lang-reference

Related Issues


Associated WorkItem - 370944

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions