Closed rmantel23 closed 5 months ago
Both of those are true. The ReadLine
method is defined to state that it can return a string
value or null
. Since the compiler has to accept that, and it ignores the practical reality, we must handle that possibility even if it can't in practice happen. I've added an improvement item here:
https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-101---getting-text-input-from-the-user-and-page-120---null-coalescing-operators
Hi Mark. Understood they are both true, and thanks for adding the improvement, but wouldn't it be better to use something else than ReadLine() on page 120 to explain the Null-coalescing operators? It just seems clearer to not use the same example to explain two different solutions (Null-coalescing operators vs. the null forgiving operator). You actually repeat the same information from page 101 on page 157 and 158 (explaining ReadLine() cannot be null normally).
What if I changed the method to GetAuthorName
?
Yes, I think that would be an improvement. And you wouldn't have to go into the details of explaining why ReadLine() can return null but normally won't.
On page 120 you use ReadLine() as an example of a method that can return null.
However, on page 101 you state: