Specify record struct initialization (#27595)

This commit is contained in:
Bill Wagner 2021-12-16 08:41:03 -05:00 коммит произвёл GitHub
Родитель 390ba1e455
Коммит 3fe194cd5a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 1 добавлений и 33 удалений

32
.vscode/settings.json поставляемый
Просмотреть файл

@ -1,32 +0,0 @@
{
"markdown.docsetName": "dotnet",
"markdown.docsetRootFolderName": "docs",
"markdown.docsetLanguages": [
".NET Core CLI",
"ASP.NET (C#)",
"ASPX",
"Azure CLI",
"Bash",
"C#",
"C++",
"Dockerfile",
"F#",
"HashiCorp Configuration Language (HCL)",
"HTML",
"HTTP",
"Ini",
"JavaScript",
"JSON",
"Kusto",
"Markdown",
"PowerShell",
"Protocol Buffers",
"Razor CSHTML",
"SQL",
"VB.NET",
"XAML",
"XML",
"YAML"
],
"git.ignoreLimitWarning": true
}

Просмотреть файл

@ -45,7 +45,7 @@ The formula is based on the mean temperature on a given day and a baseline tempe
:::code language="csharp" source="snippets/record-types/InterimSteps.cs" ID="DailyRecord":::
The preceding code defines a *positional record*. The `DailyTemperature` record is a `readonly record struct`, because you don't intend to inherit from it, and it should be immutable. The `HighTemp` and `LowTemp` properties are *init only properties*, meaning they can be set in the constructor or using a property initializer. If you wanted the positional parameters to be read-write, you declare a `record struct` instead of a `readonly record struct`. The `DailyTemperature` type also has a *primary constructor* that has two parameters that match the two properties. You use the primary constructor to initialize a `DailyTemperature` record:
The preceding code defines a *positional record*. The `DailyTemperature` record is a `readonly record struct`, because you don't intend to inherit from it, and it should be immutable. The `HighTemp` and `LowTemp` properties are *init only properties*, meaning they can be set in the constructor or using a property initializer. If you wanted the positional parameters to be read-write, you declare a `record struct` instead of a `readonly record struct`. The `DailyTemperature` type also has a *primary constructor* that has two parameters that match the two properties. You use the primary constructor to initialize a `DailyTemperature` record. The following code creates and initializes several `DailyTemperature` records. The first uses named parameters to clarify the `HighTemp` and `LowTemp`. The remaining initializers use positional parameters to initialize the `HighTemp` and `LowTemp`:
:::code language="csharp" source="snippets/record-types/Program.cs" ID="DeclareData":::