markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
564 stars 164 forks source link

Page 236 - DateTime.UnixEpoch #46

Closed rmantel23 closed 2 months ago

rmantel23 commented 2 months ago

Maybe DateTime.UnixEpoch is not the best example for a Read-only field, because working through the chapter the reader would have just changed the TargetFramework to netstandard2.0, and UnixEpoch is not available until 2.1.

markjprice commented 2 months ago

Thanks! I have added an improvement item for this here: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-236---understanding-members

rmantel23 commented 2 months ago

Thanks again Mark!

Maybe another idea. When reading this section, one could wonder why .NET wouldn't use a constant instead of a read-only field for something like UnixEpoch, since it is obviously a fixed value. I assume the answer is that only the C# built-in types may be declared as const. It might be helpful to add this where you explain the constant.

markjprice commented 2 months ago

Constants have to be literal values. Although UnixEpoch is, as you say, a "fixed value", it cannot be expressed as a literal value. I explain this in the detailed section about constants but I agree it might be useful to also briefly mention it earlier in the introductory section. I've updated the improvement item.