Would I really want to return the minimum date?
Posted
by
Clay Shannon
on Stack Overflow
See other posts from Stack Overflow
or by Clay Shannon
Published on 2012-06-08T16:15:18Z
Indexed on
2012/06/08
16:40 UTC
Read the original article
Hit count: 233
An old work colleague used to quote his father about tools, "You have to be smarter than it."
In the code below, Resharper is telling me, "Value assigned is not used in any execution path" (pointing to the first line). If I accept its offer of help, dt is not assigned a value ("today").
Is this a case where "I have to be smarter than it" and ignore their warning, or is this a case where the tool is smarter than me, and I'm just not understanding it?
My take on the situation is that if the if statement fails, the current date is returned (the default value I want), but if I acquiesce to Resharper's "demands" it would return the default value for Datetime, which is the minimum date, which I assume is something like 7/4/1776 or 1/1/0000 or so.
DateTime dt = DateTime.Now;
if (!(DateTime.TryParse(substr, out dt))) {
using (var dtpDlgForm = new ReturnDate("Please select the Date that the file was created:")) {
if (dtpDlgForm.ShowDialog() == DialogResult.OK) {
dt = dtpDlgForm.ReturnVal;
}
}
}
return dt;
© Stack Overflow or respective owner