Add item for page 69

This commit is contained in:
Mark J Price 2023-03-07 16:05:17 +00:00
parent ef5aedceea
commit 2d28545817
2 changed files with 30 additions and 2 deletions

View file

@ -4,6 +4,6 @@ If you find any mistakes in the seventh edition, *C# 11 and .NET 7 - Modern Cros
[**Errata** (33 items)](errata.md): Typos, tool user interface changes, or mistakes in code that would cause a compilation error that prevents a successful build.
[**Improvements** (16 items)](improvements.md): Changes to text or code that would improve the content. These are optional.
[**Improvements** (17 items)](improvements.md): Changes to text or code that would improve the content. These are optional.
All errata and improvements will be included in the 8th edition planned for publishing in November 2023. To be included they must be submitted by mid-September 2023.

View file

@ -1,7 +1,8 @@
**Improvements** (16 items)
**Improvements** (17 items)
If you have suggestions for improvements, then please [raise an issue in this repository](https://github.com/markjprice/cs11dotnet7/issues) or email me at markjprice (at) gmail.com.
- [Page 69 - Raw interpolated string literals](#page-69---raw-interpolated-string-literals)
- [Page 86 - Getting text input from the user](#page-86---getting-text-input-from-the-user)
- [Page 128 - Rounding numbers](#page-128---rounding-numbers)
- [Page 149 - Writing a times table function](#page-149---writing-a-times-table-function)
@ -19,6 +20,33 @@ If you have suggestions for improvements, then please [raise an issue in this re
- [Page 654 - Making controller action methods asynchronous](#page-654---making-controller-action-methods-asynchronous)
- [Page 655 - Exercise 14.2 Practice implementing MVC by implementing a category detail page](#page-655---exercise-142--practice-implementing-mvc-by-implementing-a-category-detail-page)
# Page 69 - Raw interpolated string literals
> Thanks to [Mahdi Jaberzadeh Ansari](https://github.com/mjza) who raised this issue on [6 March 2023](https://github.com/markjprice/cs11dotnet7/issues/36).
In the example JSON used to illustrate a raw interpolated string literal, the comma after `"calculation"` should be a colon. Since we never use the JSON, it doesn't actually matter, but it would definitely be better as valid JSON, as shown in the following code:
```cs
var person = new { FirstName = "Alice", Age = 56 };
string json = $$"""
{
"first_name": "{{person.FirstName}}",
"age": {{person.Age}},
"calculation": {{{ 1 + 2 }}}"
}
""";
Console.WriteLine(json);
```
And therefore the output should be:
```
{
"first_name": "Alice",
"age": 56,
"calculation": "{3}"
}
```
# Page 86 - Getting text input from the user
In Step 1, I note that the `ReadLine` method is declared to return `string?`, meaning that it could return a `null` value instead of a `string` value (including an empty one). I also note that this is treated as a warning by the compiler.