Just how old are you, Jon?
Chapter 2: Core foundations: building on C# 1: P53, listing 2.6
Last updated: 9/18/2013
Eagle-eyed readers may have noticed that in listing 2.6, I claim to be 31 years old, whereas in later listings throughout the book I'm 36 or 37. Sad to say, it's the latter age which was correct as the third edition went to print - I was born in June 1976. These days I can barely remember what it was like to be 31.
In fact, this was a problem in the second edition as well. It seems that chapter 2 is a chapter of eternal youth, basically. All the code works - it's just the data is inconsistent between listings.
This actually raises an interesting point about storing time-sensitive data: always try to store a fixed reference point rather than a dynamic value. If I'd had a
DateOfBirth property instead of an
Age property, nothing would have needed updating between editions at all. That's what I'd have done for real code, but
Age = 37 is a good deal shorter than
DateOfBirth = new DateTime(1976, 6, 19) even leaving aside the thorny issue of how suitable
DateTime is for storing a date.