I can honestly say I love where I work. And today was a classic example why. I had a code review! (does your team have code reviews?). One of my colleagues pointed out I could make use of Nullable GetValueOrDefault() in the following code snippet:
Instead of this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: green; }.cb3 { color: #2b91af; }
int? objectID; // passed in to a method...
DateTime? signedDate; // --- "" ---
if (objectID == null)
{
objectID = 0;
}
if (signedDate == null)
{
signedDate = (DateTime)SqlDateTime.MinValue;
}
SomeDBWrapperMethod((int)objectID, (DateTime)signedDate);
Just do this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: #2b91af; }
SomeDBWrapperMethod(objectID.GetValueOrDefault(),
signedDate.GetValueOrDefault((DateTime)SqlDateTime.MinValue));
Seems so obvious, after the fact! I’m sure I must have come across this before, but I can’t remember having ever used it. It’s great to have extra pairs of eyes go over your code.