-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
If the generated auto-implemented property definition isn't what you want, you can define your own property of the same name. If you do that, the generated constructor and deconstructor will use your property definition.
No, it will not be used by generated .ctor.
> record Rec(int Int, string String, double Double)
. {
. public int Int { get; } = int.Parse(String);
. public string String { get; } = Int.ToString();
. public double Double { get; }
. }
> new Rec(1, "3", 4.4).ToString()
"Rec { Int = 3, String = 1, Double = 0 }"
It also gets some kind of formula few words later.
You must add the explicit assignment of the declared property to its corresponding positional parameter.
This sentence is also of course wrong since source-destination dependency is exactly opposite.
This whole paragraph deservers rewording. For instance
For instance, the following example declares the FirstName and LastName properties of a positional record public, but restricts the Id positional parameter to internal.
becomes little esoteric.
Example bellow is also little beside point when showing some output and Main
not relevant to explicit property declarations.
Part with deconstructor is correct.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 20818c64-4ad8-fb15-5d79-e7f98614e9c4
- Version Independent ID: de1f383b-ef20-4776-57a8-04edae892166
- Content: Records - C# reference
- Content Source: docs/csharp/language-reference/builtin-types/record.md
- Product: dotnet-csharp
- Technology: csharp-language-reference
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn