I've just written the following code:
DateTime? toDate = null;
DateTime.TryParse(TextBoxDate.Text, out toDate);
Which of course won't compile because TryParse expects a DateTime, rather than a (nullable) DateTime?
So I'm now using a some what less tidy if/else block.
Question is - Have I missed the point of TryParse? Surely starting with a null value, then assiging that value to a variable/struct if the supplied value successfully converts, is what its for?
To put this in context, the date is optional for the user, if entered I then build my SQL with date criteria...or not if no date supplied - Which is where I was going to work on the value of toDate- null or a date if one was used.
I could of course initialise DateTime to an unlikely date, but this doesn't seem the right thing to do.
Any help/advice appreciated!
View Complete Post