IsDate functionality in C#

At the client I’m at now I’m using VB.Net (I’d prefer C#, but it’s not my call).  I was stepping through some code and had the IDE set to stop “When an exception is thrown” (see the Debug menu under Exceptions; this is handy when you want to catch exceptions that may be getting masked by other exceptions down stack).  All of a sudden the IDE popped up a “First Chance exception” window on a line using the VB IsDate function.  The exception complained about the input string not being in the correct format.  The parameter was indeed not a date, but I thought that is what IsDate was supposed to do….tell if it is a date or not….this just boggled me for bit until I noticed I could type “? Isdate(”121”)” into the command window in the IDE and it returned False , not an exception. 

I had a pretty good idea of what was going on, but to be sure I popped open ILDasm and took a peek what IsDate was doing in IL code.  It was attempting to create an instance of a datetime object using the input string, then if that threw an exception it just returned false.  The IDE was stopping because I had told it stop whenever an exception was thrown.

I bring this up (and the reason for the post title dealing with C#), is because I’ve seen several posts and fielded some questions about how to determine if a string is a date in C#.  One option is attempt to do a DateTime.Parse on the object and wrap that in a try statement.  If it fails to parse it is not a valid date.  The second option I’ve read is to actually reference the Microsoft.VisualBasic assembly and call IsDate.  Well, now we know that IsDate is doing exactly what the first option would do.

So, if asked now what to determine if a string is a valid date in C# I would recommend to attempt to parse it and put a try catch around it.  If you do this a lot then I would suggest either putting this code in your own custom, C# version of IsDate or if you do it A LOT, then I would suggest you do the work on your own to determine if the string is date rather than rely on exceptions to control your flow.

Thoughts?