|
-
Aug 30th, 2012, 06:16 PM
#1
Thread Starter
Hyperactive Member
Re: DateTime format validation method using DateTime.TryParse() always returns false?
If you're not going to do anything with the result of a .TryParse in VB.NET you can set the result to Nothing rather than creating a temporary variable you need to get rid of.
Good call on that. Actually up until now I've never considered having Nothing as the return on a .TryParse(). Thanks!
-
Aug 30th, 2012, 07:32 PM
#2
Re: DateTime format validation method using DateTime.TryParse() always returns false?
 Originally Posted by DavesChillaxin
Good call on that. Actually up until now I've never considered having Nothing as the return on a .TryParse(). Thanks!
It's not that you're using Nothing as the return. The return value is a Boolean regardless. The output parameter is a DateTime. If you pass Nothing to that parameter then, inside the TryParse method, it will receive the default value for the DateTime type, which is #1/01/0001#. If the conversion works then the method will assign the appropriate DateTime value to the parameter and that is what the method outputs. The only difference is that, because you used a literal rather than a variable, you don't have access to that output value.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|