Forehead slapper on DateTime.AddDays()
I should have read the documentation for DateTime.AddDays() a little more carefully. This one caused a minor bug for me this week:
DateTime dt = DateTime.Now;
dt.AddDays(1);
What's in dt after the call to AddDays()? Well I assumed it would be this time tomorrow. However, from the .NET documentation for AddDays() I finally noticed: "This method does not change the value of this DateTime. Instead, a new DateTime is returned whose value is the result of this operation." Doh!
I should have written
DateTime dt = DateTime.Now;
dt = dt.AddDays(1);
That's what I get for not reading the docs, and instead assuming from the function's name that I know what it does (one of the downsides of Intellisense is it almost makes finding functions too easy). Although I'm not sure what would I have called the function AddDays() so its behavior would be more clear. Maybe something like: DateTime.ReturnNewDateTimeWithThisNumberOfDaysAddedToIt()...nah maybe not.